Showing posts with label ATtiny. Show all posts
Showing posts with label ATtiny. Show all posts

Saturday, February 8, 2014

DHT11 on ATtiny85

Recently I got my DHT11 temperature and humidity sensor working with my Arduino Mega2560. If you are interested in that, check it out HERE. However, while that was all well and good, I found it a bit impractical. While I may someday decide to create some sort of weather logger using the DHT11, it is unlikely that I would dedicate an entire Arduino to the task. Enter ATtiny85.

The ATtiny85 is great because it is cheap, but the real question is, "Does it work with the DHT11?" Yes it does.

Now in my last post I used the DHT library from Adafruit. While that library served its purpose, it does not work with the ATtiny. Don't ask me why; I did not explore it. HERE is another report of it not working and a description of what will happen if you try it. It reads out all zeros.

What does work is the DHT11 library. To get it working you will need to modify the example code. Basically, you need to change everything that says "Serial" to the Software Serial equivalent. This will allow us to get the sensor readings back from the ATtiny. If you want more information on serial communication on an ATtiny, check out THIS post. Alternatively, you could just download my code (HERE), wire everything the way I say, and see if it works.

Now when you go to compile my example, there is a good chance you will run into a problem. As it turns out,  there is an issue with the tiny core when trying to compile sketches close to the maximum sketch size. Luckily there is a quick and easy fix. I won't go into the details, but follow the instructions HERE.

When that was straightened out I was able to upload my sketch successfully. I used my USBtinyISP and my ATtiny85/45 programming adapter.


The only thing left to do is wire it up and see the output. Basic wiring of the DHT11 is the same as in my last post.

Correct Wiring:
Pin 1: +5V
Pin 2: Signal. Connect to digital IO with a 5k ohm pull-up resistor
Pin 3: Nothing. Some people suggest grounding it if you run into trouble
Pin 4: GND

On the ATtiny side, PB3 is the software serial Rx and PB4 is the software serial Tx. Connect those to an FTDI (or some other serial receiving device). Connect 5V and ground.


Power it up and watch the show!



This of course could be modified to do other things with the temperature data. It could, for instance, transmit them via I2C. Maybe it could log them on an SD card. Those projects I leave to you (for now anyway). If you are interested in more ATtiny projects of mine, check out my ATtiny label. Let me know if this works or doesn't work for you. As always, I'm happy to help.

-Matthew

Sunday, January 19, 2014

Stepper Motors and ATtiny: 28BYJ-48, ULN2003, and ATtiny85

Today I will be taking some time to briefly revisit stepper motors. Recently I have been trying to map out the boundaries of my ATtiny capabilities, and it occurred to me that I have never gotten my stepper motor working with one. Eager to fix that I broke out my ATtiny85 and my 28BYJ-48 Stepper motor and went to town.

First things first, I already did a post on the 28BYJ-48 with a ULN2003 motor controller for the Arduino (HERE) and won't repeat the information listed there. If you are having trouble getting the motor to work on an ATtiny85/45, I recommend you go back and check out my other post. It has lots of useful links and tips.

If you need instructions on getting the ATtiny running with the Arduino IDE, check out my ATtiny label. For this post I will be using the Arduino Tiny core from Google Code. It runs on Arduino 1.5. For the programmer I will be using a USBtinyISP with my ATtiny85/45 programming adapter.

This really turned out to be pretty straight forward. Using the same Small_Stepper.ino example from my last post, I changed the pins to the correct values and everything worked (get my ATtiny sketch HERE). The motor turned nicely. One note about wiring, you can't actually wire this stepper the way that you define it. There are comments about this in my sketch, but for those that don't download the sketch, reverse the 2 middle wires. If you don't reverse the 2 middle wires the motor will not turn in reverse. If you want a longer explanation as to why and a complicated fix, go to THIS forum post. I just reversed the wires.

Example: Stepper small_stepper(STEPS, 0, 2, 1, 3);    implies that you connect ATtiny pins 0, 2, 1, and 3 to pins IN1, IN2, IN3, and IN4 respectively. For this motor you should  connect ATtiny pins 0, 1, 2, and 3 to pins IN1, IN2, IN3, and IN4 respectively.


Since that was so easy, I decided to do something else as well. I made a stepper version of the Knob example. Some readers may know that such an example already exists in the Arduino IDE, but I wasn't happy with the way it worked with my motor. My sketch works a little differently. As you can see from the video below, as I turn the knob, the speed of the stepper changes. If you want the sketch, you can get it HERE.


There you have it. Controlling a stepper motor with an ATtiny85 is not only possible, it is easy. If you run into problems or use this post to great success, let me know. I hope this post turns out to be somewhat useful.

-Matthew

Thursday, January 9, 2014

I2C HC-SR04 Sonar Module: ATtiny85 I2C

In this post I will show you how to cheaply  make an I2C sonar sensor for your Arduino. This will be accomplished by making an I2C controller for an HC-SR04 sensor out of an ATtiny85 (or ATtiny45). Both the sensor and the microcontroller can be found online for a few dollars. Together these two parts can save you money while increasing functionality over premade solutions.

If you have not already done so, check out my previous post on a serial sonar sensor. It also discusses running the NewPing library on an ATtiny (my modified TinyNewPing library). I have also done a post on I2C communication. In fact, I even transmitted data from my PING sensor! Check it out HERE.

1) First off, we need an I2C library for your ATtiny. For this you have a few options, but I will only be using one of them. The regular Wire library will not work on the ATtiny side. However, thanks to some great work  by Arduino users BroHogan and Rambo we do have the TinyWire library. The original library by BroHogan can be downloaded HERE. I have used the Master library from it, but for the Slave library I will be using a fork by Rambo. He added a bit more functionality including an onRequest and an onReceive function (which I use in my examples). Find his library HERE (download zip link is in the bottom right corner).

You will also need the ATtiny core for whatever Arduino IDE you are using. In the past I have used the core from High-Low Tech. Now however I prefer the Google Code core. A recent update allows ATtiny support with Arduino 1.5. Anyway, if you need more details on getting an ATtiny running see my previous posts linked above or click on the ATtiny label.

You need to burn your ATtiny85/45 to 8MHz. This is important for stable I2C communication (consider making my ATtiny programming adapter!). You also need my TinyNewPing library installed.



2) Wiring is simple. Connect the 5V from the Arduino to the VCC of the ATTiny and the PING sensor. Connect all the grounds together. Then connect the Trigger and Echo pins of the PING sensor together and to pin 3 (PB3) of the ATtiny85. Next connect the I2C wires. Connect the ATtiny SCL (PB2) to the Arduino SCL (Arduino Uno: A5 , Arduino Mega2560: 21 , Arduino Due: 21). Connect the ATtiny SDA (PB0) to the Arduino SDA (Arduino Uno: A4, Arduino Mega2560: 20 , Arduino Due: 20). Finally, and very importantly, connect 4.7k (on 5V) ohm pull-UP resistors to the SCL and SDA lines.





3) Now you have the libraries installed. Everything is wired up. The only thing left to do is test it. THIS code goes on the ATtiny. It reads one HC-SR04 sensor and acts as the I2C slave. THIS code goes on your other Arduino. I used a Mega, but you can use whatever you have. It requests the data from the slave and then outputs it to the serial monitor.

That is about it. Assuming everything works, you are ready to go. Using this method, you should be able to get sensor data from many sensors at once using only 2 pins on your Arduino. One thing to remember, since they are not all being controlled by the same Arduino, the sensors are not synchronized. As such, they could interfere with each other if they are pointed in the same direction.

Also, I attempted to control multiple sensors with one ATtiny. This worked, sort of. It was buggy and crashed after 15 seconds or so, I suspect do to a I2C buffer issue. Regardless, it made the code more complicated on both sides and the system wasn't as reliable. Besides (I said to myself), ATtinys can be found fairly cheap (especially surface mount ones). My time is worth something. While I got tired of messing with it, if someone else gets it working let me know. I'd be interested to see your code.

There you have it. A cheap I2C ultrasonic ranger for an Arduino (or I2C master device of your choice). If you use this approach in any of your projects I would love to hear about it in the comments. Of course, if you have problems I will do my best to help you with them.

-Matthew

Wednesday, August 7, 2013

Serial Sonar Sensor: ATtiny85, HC-SR04, and Arduino SoftwareSerial

In this post I will detail how I used an ATtiny85 as a controller for an HC-SR04 sonar module (Ping sensor). The controller reads the inputs from up to 3 HC-SR04 modules and transmits the readings to an Arduino Mega via serial communication. This allows the Arduino Mega to pick up the readings whenever it is convenient rather than having to worry about complex timings. Let's get started


First things first, we need to run the NewPing library on an ATtiny85/45/25. Until version 1.6 is released you will need to modify the library to do this. However, this removes some of the functions you might want to use on other boards. For this reason, I created the TinyNewPing Library. In it, I removed the parts that cause the errors on an ATtiny and gave it a new name so you can distinguish between the two. All the function names remain the same. If you still need more details check out THIS prior post.

Next we need the SoftwareSerial Library on the ATtiny. Luckily, this comes with the IDE and I already did a post on it. Funny how that works.

For a first attempt, try a single HC-SR04 sonar sensor. This simplifies the code a bit. Load THIS code on the ATtiny (sensor side) and THIS code on the Arduino Mega. Note the code uses both Serial and Serial1 (thus the Arduino Mega).

To wire it up, connect the echo and trigger pin together and then connect them to pin 0. Wire in 5V and ground to both the ATtiny and the HC-SR04. Then connect pin 4 (Software Tx) on the ATtiny to pin 19 (Rx1) on the Mega. Finally, plug the Mega into the computer via USB.

Now if this is working ok, we can move on to 3 sensors. For that, we need to load THIS code onto the ATtiny and THIS code onto the Arduino Mega. The ATtiny takes the readings and sends them to the Mega. The Mega updates it's variables and sends them to the Serial Monitor for us to see.

Wiring it is cumbersome but simple. Regrettably, I did not take a picture when I did it, but just do what you did before an extra two times. Note again that we are using the same pin for trigger and echo, so they need to be wired together. Then wire up power and grounds. Finally connect the ATtiny to the Mega and the Mega to the computer.

Now open the Serial Monitor and watch the numbers scroll by.

Potential problems: If the ATtiny gets out of sync with the Mega (it will), an occasional bad value will come up. I couldn't come up with a quick fix for this. If that is a problem, maybe you could take the median of a few readings. They are coming in pretty quickly. The plan is to make an I2C version of this soon, but I make no promises on a deadline. One last download, get the entire package of sketches used in this post in a zip file HERE.

A few quick notes before we go.

  • Why not I2C? That's next (Done! Check it out HERE). Serial is easier because it doesn't require a 3rd party library to work on the ATtiny line. 
  • Why only 3 sensors? Short answer, ease of use. You might be able to get 4 or even 5 out of an ATtiny45 if you're persistant. I don't have that many sensors nor that much patience. You have 5 regular IO pins plus the reset pin (which can be used as an IO). You might be able to use the serial Rx pin as an input as well. 
  • Why not just buy a I2C ping sensor and be done with it? Well this reduces the number of wires going to the Arduino Mega. It also gives you more options and increases the number of micro controllers on board your robot (cool factor). Other than that, it's cheap. With HobbyKing or Ebay, this project could be done for less than the price of one I2C sonar sensors.
Hopefully someone will find this useful. If anything goes great, please comment! If anything goes wrong, contact your local internet service provider. I blame them (That's a joke. You can comment below as well).

-Matthew

Friday, July 19, 2013

Whirly-Gig: Charlieplexing and SoftwareServo on ATtiny45

I recently completed a project involving an ATtiny45 and wanted to share it with the world. The idea came from the world of FIRST robotics. At competitions some teams have spinning banners ("whirly-gigs") above their pits to attract scouters, judges, and anyone else who might be interested. I had a friend who saw it and told me to make one for her birthday. Sounds like fun! Let's get started.

Hardware involved:

  • 1: ATtiny45
  • 1: HXT900 Servo (modified)
  • 1: Momentary Switch
  • 1: 10k Potentiometer
  • 1: 5V Voltage Regulator
  • 1: DC Power Jack
  • 1: 2 Way Switch
  • 1: 3 Battery AA Holder
  • 6: 5mm Colored LEDs
  • 3: 270 Ohm resistors
  • Wire
Software Involved
First, the ATtiny core. I have done several posts involving ATtinys in the past. Follow the instructions from the link above to use an ATtiny with the Arduino IDE.

Second, the SoftwareServo Library on the ATtiny. I have already done a post on controlling servos with an ATtiny. Find it HERE. Basically, the regular Servo library will not work because it doesn't have the necessary timer, so SoftwareServo must be used.

Next we have the Charlieplex Library. It takes care of setting the pins correctly to turn on the LEDs we will be using. I have done a post on this library as well. Find it HERE.

Last we come to my sketch. You can get it HERE. It may be a bit convoluted , so I tried to comment it to be understandable. The essence is this, there are 10 different LED modes that the user switches between by pushing a button. At the same time the servo which has been modified for continuous rotation as discussed HERE is controlled by turning a 10k pot.

I made a nice wooden base for the electronics and mounted the servo on 2 wooden uprights. The sign itself is made of dowel rods and home insulation foam cut into circles. I made it such that an 8.5 x 11 sheet of paper will fit on it when rolled horizontally.

I soldered together all the electronics. I put a 270 Ohm resistor on each LED pin. I also put a 10 uF electrolytic capacitor across the power leads and a diode protecting against unwary users plugging in power backwards, but those probably aren't necessary.

I did run into one problem in the course of this process. The servo would stop working when I set a certain LED pin LOW. I never did get to the bottom of it, but it is discussed in THIS forum thread. I ended up changing the pins I was using, and it solved the problem. I included a diagram of my pinout in the code posted above.

That's about all the details I am going to give you. The whole project took quite a while, and it's a DIY project. I'm not selling kits. If you want, you can view my project photos HERE, and I took a nice video for you to look at. I hope I inspired you to greatness.



-Matthew

Thursday, June 13, 2013

Serial Communication on a ATtiny85 with the SoftwareSerial Library.

"Serial is giving me errors on my ATtiny! What can I do?" We have a solution.

Serial communication is not difficult on an ATtiny thanks to the SoftwareSerial Library. While the ATtiny85 does not have the hardware of a "real" Arduino, it can still function in similar fashion. If you're just getting started with using an ATtiny, here are some resources you might need.

  • Information on programming them from High-Low Tech. You can also look back at my previous posts.
  • My nifty programming adapter. A few minutes of soldering made my life much easier.
  • My USBtinyISP is discussed in THIS post. It also makes life easier.
  • Previous posts on Running Servos and the NewPing Library on an ATtiny.
  • THIS previous post mentioning my USB to UART converter cable
Now we are ready to go. First things first, I am using Arduino 1.0.4. The SoftwareSerial Library is included as a default library, so there is no reason to get a 3rd party library.


Step One: Wire it up. With my USB to UART cable it is as follows.
  • Black: Ground
  • Green: Tx (using Tx as pin 4)
  • White: Rx (using Rx as pin 3)
  • Red: 5v (this is optional if you have an external power supply)
Connect an LED with appropriate resistor to pin 1.

Step Two: Ensure that your ATtiny is burned to run at 8MHz. Now load THIS sketch onto the ATtiny. Note that parseInt() works with the SoftwareSerial Library.

Step Three: Open the Serial Monitor and set it to the correct Baud rate. To reset the ATtiny, bridge the reset pin to ground momentarily. When you see the connected message, enter an integer and count the flashes.

That's all there is to it. I you don't have a USB UART cable, this is easily adaptable to communication with another Arduino with a USB port. See THIS post for code. If you want to see a practical application of serial communication on an ATtiny85, check out my serial sonar controller HERE.

Hope this works for you all. As usual, if there are any questions, just let me know.
-Matthew

Sunday, April 28, 2013

Using Reset pin as IO on ATtiny85/45 with avrdude and USBtinyISP

Today I'm going to discuss my successful attempt to use the reset pin of my ATtiny45 as an IO and then change it back again. I'm not going to go into a lot of detail because, a) I'm not an expert and b) other people already have. I'll just provide links to the useful pages.

The theory behind this is pretty simple. Basically, you change some fuse bits and the reset pin becomes pin 5. Unfortunately, this means you can't program it with a ICSP (like the USBtinyISP) anymore. You need a High Voltage Serial Programmer that supplies 12v to the reset pin before changing the fuse bits. There are several Arduino forum threads on this out there. Chances are you found those before you found this blog. Now lets get started.

1. You need to get some software. Follow the instructions from Ladyada to install WinAVR

2. You need load a test sketch into your ATtiny with your USBtinyISP or other programmer. I'm assuming you know how to do this. If not go HERE. I used blink with the pin changed to pin 5. If you load it and wire up the LED you shouldn't get any light.

3. Now you need to enable the reset pin as an IO (and thus lose programming capability). This is slightly involved. I recommend you see more instructions from Ladyada. They are very in depth and useful. If you want bare bones you can look below.
  1. Find a fuse calculator. I used THIS one. Select the options you want. I used default with reset disabled. Copy the AVRDUDE arguments.
  2. Open a command window by searching for cmd in the start menu.
  3. Type the commands to set the fuses: avrdude -c [insertyourprogrammerhere] -p [enteryourboardhere] -U [enter the arguments you previously copied here].  Example: If you are using an ATtiny45 and a USBtinyISP like I am (and are extremely lazy), copy and paste this line into the command window:     avrdude -c usbtiny -p attiny45 -U lfuse:w:0x62:m -U hfuse:w:0x5f:m -U efuse:w:0xff:m
  4. Watch and wait. You should get a nice thank you message. You're done.
You're reset pin should be acting like an IO now. If you plug in your LED now, it should blink nicely.

That's great! You know have 6 IO pins at your disposal, but you want to load a new program onto the chip. You need a HVSP. Go forth and Google search. To save you some time here are the cheap options out there.
My Arduino resetter circuit. 
I ended up using the last one, and it does work. All you need is a breadboard, jumpers, 6- 1k resistors, a 2N3904 NPN transistor (I found one on an old cordless phone), and an Arduino. You'll also need some source of 12V. Anyway, you pretty much just follow the instructions on the webpage above. After I discovered the bad jumper I was using, it went smoothly. 


When you finish, the LED on the reset pin should no longer work, but you will be able to program the chip again. This is good. You have successfully reset the fuses.

That's about all I have for this post. I hope you found it useful. Be sure to check out those other websites. They have a lot of good information.

-Matthew
Here's another picture.

Friday, April 26, 2013

Breadboarding a Surface Mountable ATtiny85

I previously mentioned, I recently made a purchase from Mouser.com. Today I wanted to make a quick post about one of my purchases.

I had planned on ordering a few ATtiny85's when ordered the stuff for my ATmega328 breakout. Unfortunately, the dip package was out of stock, so I did the next best thing. I ordered a few ATtiny45's and some surface mountable ATtiny85.

ATtiny85-20 SU vs SH
They had two that caught my eye. ATtiny85-20SU and the ATtiny85-20SH were $0.83 and $1.18 respectively. Honestly. I had no clue what the difference was, so I ordered a couple of each.

I received them and finally set about playing with them a few days ago. To the right you see a picture of the two different kinds. Don't let the picture deceive you. They look the same. I'm not an expert on such things. If someone knows what those letters mean let me know and I'll update this post.

UPDATE: Jason the PC MD says that the pins are made of different materials. This would make sense. Tin is cheaper.
SH:NiPdAu
SU: Tin

Regardless, I wanted to put them on a breadboard to play with. There are several ways to do this. Ideally, I would make a little PCB and solder it together. Maybe someday I will get into etching, but that day is not today. I have also heard of surface mounting protoboard which has smaller spacings to accomodate surface mounted parts. I'm sure there are other methods as well (I saw something about drawing with a conductive pen.. Not going there). Anyway, I had none of these methods available, so I broke out the soldering iron and went to town.

I started with a small piece of protoboard that I cut to size with an x-acto knife and sanded smooth.


Next I snapped off some male headers and placed them in a solder-less breadboard to insure they stayed straight. I randomly decided that I would use an ATtiny85-20SU and then began to very carefully solder each pin to the corresponding header. I used the same small Kynar wire that I used for my ATtiny programming adapter (which if you haven't seen, you should check out. It makes my life much easier when I program the ATtiny DIP sockets).


When I got done I squirted a good bit of hot glue under the ATtiny itself just to make sure it didn't move around and short out. I also super glued the headers to the protoboard because the pins aren't plated all the way through on this cheap protoboard, and I didn't want them to pull off with repeated use.


I have no doubt that this could be done more compactly. This is not pretty and won't work with my previously mentioned adapter, but it gets the job done. I have tested it; it works fine. As for SH vs SU mounting types, I still don't know. We will see what time reveals.

Also, this weekend is the FIRST Robotics Championship in St. Louis. If you don't know what that is, check out the website usfirst.org. The competition will be streaming live as well. That can be found HERE. I know from first hand experience that it is a lot of fun. If you ever get the chance to go to one of the events, you won't regret it. They are all free and open to the public.

-Matthew

Saturday, April 6, 2013

NewPing library on ATtiny

Well now we have come to the point where I need to address Problem 3. If you don't remember that one, it was mentioned back a few post ago.

We need to run the NewPing library (for my HC-SR04) on the ATtiny85. First things first, we will need some code to test it with so we know it is working. It doesn't have a convenient serial interface like the Mega. Enter NewPingLED.

Its purpose is to turn on an led when an object gets within 20cm of the sensor. This is something that the ATtiny85 can manage.

Next, I got it running on my Mega. Not too difficult. I did note that this sensor was a lot less accurate (and precise) than the other ones I got. Sometimes you get what you pay for. It was like $2.50 on Ebay.

I posted a video in case you don't believe me. Obviously, the Mega can also run any of the example programs that come with NewPing 1.5 as well.


Now on to the ATtiny. Well the code doesn't compile right out of the box. The problem is with some of the timers that the ATtiny doesn't have. This is discussed HERE. It sounds like a fix will be coming up shortly in version 1.6, but in the meantime you just have to comment out the stuff about the timers. If you want the library with that stuff pre-edited out, its HERE. Note that you won't be able to use those parts of the code on any other board until you change it back. Hopefully 1.6 isn't far away.

Now that we have that out of the way, we just need to change the pins to something usable, get rid of the serial stuff, and wire it up. I'm going to assume you can handle that (remember the resistor on the LED!). If you are having trouble with basic wiring and such, check out Jeremy Blum's stuff HERE.

The new code is HERE. As you can see, it works well. It's no miracle of science, but it's a step toward doing what I want to do. Just for fun I also did a Fade program. Next, I think it would be cool to do some basic communication with my Mega. Sending Ping values back and such. I also have some other projects on my mind though.


In case you didn't know, next week is National Robotics Week. That's sure to be a blast. Also, in the world of FIRST robotics, nationals are coming up. Be sure to check out the webcast HERE. There are sure to be some awesome Frisbee shooters there.

That's all I have for now. Check in again,
-Matthew

Thursday, April 4, 2013

ATtiny85 programming adapter

I've been playing with the my ATtiny85 and have been enjoying it. However, programming it can be a pain, because I have to break out the jumper wires and the datasheet to figure out which wires go where. This got annoying quick, so I got to problem solving.

This was the result. It simply plugs into my breadboard on top of the ATtiny and then rearranges the pins into a convenient 6-pin connector for my USBtinyISP. It works pretty well. I wanted to make a full Arduino style breakout board for it but had two things inhibiting that.

This stuff is junk.
One, my female headers haven't come in yet. They are in the mail, so maybe I will do that someday. Two, the cheap perfboard that I bought is cheap. It only has contacts on one side. I struggled working with it for a while. When I pulled a pad off of one contact, I gave up and got the good stuff. I switched to the stuff from HobbyKing. Now on to making your own
.

What you'll need

  • Male headers- specifically you'll need 14 pins
  • Protoboard- I used THIS stuff and it worked great. Perfect size too.
  • Wire- I used some stuff I had around. I believe it is called Kynar.
Step One: Cut the board to length. I needed a grid that was 6 x 7. However, when I switched to the HK protoboard, it was close to the size, so I used that.

Step Two: Solder on the male headers that plug into the ATtiny. It is simplest to plug it into a breadboard while you do this so that you know it will be straight and fit in the sockets.


Step Three: Solder on the male headers that plug into the USBtinyISP. I did the same thing as above and just flipped it over and soldered it in the breadboard.


Step Four: Connect the dots. This takes a little ingenuity on your part. I put the side with the RESET and GND pins on the left so that most of the pins were fairly straghtfoward. Be sure to mark it so you know which way to plug in the cable. The important thing is that   they a) go to the right places b) don't go to the wrong places and c) don't go where the ATtiny will physically be when this thing sits on top of it.


Step Five: Ring it out. Now you go through EVERY pin on the thing and make sure it goes where its supposed to (see the above charts). Next you go through EVERY pin and make sure it doesn't short out anywhere or do anything else harmful. I will not be responsible for any fried chips but my own.



Not pressed down
Now go test it out. I found it quite a bit more convenient than breaking out the charts and jumper wires every time. It's also less prone to errors. I will mention that you may need to unplug other things when loading code. Example, I had a servo plugged into pin 1 and tried to load code. The servo jumped around and the code didn't load right. Also, it probably would not be good to hook it up when the chip is under power. I don't know that for a fact but call it intuition.

Here are some more pictures in case its fuzzy just how this thing is connecting to the ATtiny. It sits on top of it.
It place and ready to go.



Well that's all I have.  I hope you find this useful. Have fun in all your endeavors

 -Matthew

Monday, April 1, 2013

SoftwareServo library - ATtiny85/45/25

This post will cover the the examples of ATtiny that come with the modified SoftwareServo library found HERE Please note that the commands themselves have not been changed. I merely changed it for IDE 1.0+ compatibility and added a few examples. For information, check it out HERE.

What you will need:

  • ATtiny85/45/25
  • USBtinyISP or other method of programming
  • Hobby servo
  • Jumper wires
  • Breadboard
  • 10K potentiometer 
First, I am assuming that you know how to load programs onto the ATtiny. If not, please refer to my last few posts and THIS link.

Second, I'm going to assume you have either tried the Servo library that comes with the IDE and know it does not work or have read my previous post.

Third, don't expect the SerialServo example to work on the ATtiny.

Configure the ATtiny: We need it to run at 8MHz. Luckily it has an internal 8MHz clock. We merely need to plug it in, select ATtiny85 (internal 8 MHz) under boards and hit burn bootloader. It should load pretty quickly.

In case you don't want to read the datasheet. (credits)
Sweep: This is the first example I added. It is very similar to the sweep example from the Servo library. Notice that you have to refresh the servo manually. This could be useful or annoying depending on your situation. Regardless, it is the nature of the beast.

Here is a diagram of how you should wire everything up. It is pretty simple. As you can see from the pinout chart above, you could change the pins somewhat. 





Knob: This too is similar to the example found in the Servo library. This requires that you hook up a 10k pot to pin 3. As you can see, you can choose one of the other analog inputs instead if you wish. 

Again, here is a diagram of how you can wire everything up.



Now in case you are one of those people that just like to see the real thing, you can check out a video of sweep HERE and knob HERE.

If you have any questions or comments, either comment here or send me an email.
-Matthew



Friday, March 29, 2013

ATtiny85 Servo: SoftwareServo Library


Well I began work on my ATtiny85, and so far it has been quite the adventure. My initial thought was that it would be cool to use one on my differential steer robot, so I plunged into making this happen.
There are several problems with this that I have seen so far.
  1.  I will quickly run out of pins. I will probably want an ATtiny84. Maybe my 2313 will work. That’s another day.
  2.   The servo library will not work on the ATtiny85, reason being that the servo library relies on a 16 bit timer whereas the ATtiny only has an 8 bit timer.
  3.  The NewPing library does not work on the ATtiny. I believe this is the case anyway. The code will not compile. I haven’t looked into why this is. I’m assuming it has to do with the timers again. (Edit: check out my post on that HERE)
 Now I set out to solve all the problems of the world.

 Well I could just use an ATmega238 chip. All of the above problems solved, but that’s cheating.

Problem One: Like I said earlier, I will probably need to change hardware for this one. However, the ping sensors can be run on one wire for trigger and echo which I am not doing at the moment because my Arduino Mega had pins to spare. That would diminish the pin count by 2. I could also get my two bumpers on the front off of one analog pin by putting a different sized resistor on each one.

Problem Two: Now it gets fun. As it turns out, way back in the days of IDE 20ish there was a library called SoftwareServo library (more info HERE). All these young whippersnappers (Me) don’t know what that is because they got that newfangled timer based Servo library. Interesting. Well this can be used to our advantage. Long story short, download the library HERE. Stay tuned if you want to hear how I changed it.

 The changes are really quite elementary. All that had to be done was in SoftwareServo.h, change
            #include  <WProgram.h>       to      #include "Arduino.h"

This is to accommodate IDE 1.0+.  For those that might not know, you can use a variety of programs to do this. I used CodeBlocks because it was what was set was the default on my computer. You could probably manage with notepad on a change like this, but I’d go ahead and download a free compiler somewhere. Just Google C/C++ compilers. I’m really not experienced enough to recommend one.

Next I went to getting it running on the ATtiny. Well it was not as convenient to do so as some other libraries because it only came with one example, SerialServo. Well this is a problem because the serial library does not run on the ATtiny85 in its current form either, but that is a problem for another day.

I went typing away and eventually got it to work, so I added a few examples for lazy people like me. I already gave a link to it, but here it is again: SoftwareServo.

The rest is pretty simple. You do need to flash the ATtiny to run at 8MHz. That takes all of 15 seconds. Just connect it up, select the ATtiny85 (internal 8 MHz) option and hit burn bootloader. Details from High-LowTech.

It works really well. It’s perhaps a bit more jumpy than running on my Mega. That will happen though. I read an explanation on why that is, but it involves math and I really don't remember the details. I just know that the cut from a 16 bit timer to an 8 bit one cuts the resolution quite a bit.

Just for reference, there is also a Servo8bit library that I tried before I found the SoftwareServo library.I don’t believe it requires the Arduino IDE. I never got it to work, but maybe others can. Find details HERE. If you get it to work, let me know. I’d like to check it out.

That brings us to Problem Three. Well that is work for the future. I mainly just wanted to get a servo up and running. I succeeded with that. Yippee. Also, I got some new components and such. I will probably do a quick post on those soon too.

Happy Easter,
Matthew

Friday, March 22, 2013

Arduino Mega as ISP- broken Arduino

Well it has been a while since I posted anything on here, and there are several good reasons for that. One, last week was spring break, and it was beautiful. I did a lot of stuff outside and never really touched my computer. Two, right before spring break I managed to break my Arduino again. Here's how.

As I have mentioned I got an ATtiny85 to play around with. I thought it would be a natural next step to start doing stuff with just the bare chip. I am by no means an expert in such things and thus went searching for someone else's work that I could shamelessly copy in the name of education. I found this website HERE and began to follow their instructions.

Now to program these chips you need an external programmer. Being a college student and not having a whole lot of money that I just long to spend, I decided to go with the Arduino as ISP route. Well you can go to the website if you don't know what that entails, but to the right there's a picture to give you a general idea. Basically you are piggybacking off of the Arduino's programmer.

This went great! I plugged in all the wires based off of the charts on the high-low tech page, followed the rest of the instructions, and clicked go. Off the races I went, loading blink. I unplugged everything but the power and ground and got a blinking light! Yay!

Now that's cool. I plugged the wires back in and loaded fade. Error. Try again. Error. Sigh.

Now I unplug everything and try to load blink onto the arduino. It took forever to try to upload. Error. I believe it was something like the one below. Its funny that I saw it so many times but never actually copied it down.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

Then I got thouroughly depressed and didn't touch it for a few days. Later I began trying to fix it.

Attempt 1: The reset doesn't appear to be working. Google such things. Nothing. Manual reset with a resistor on reset pin. Nothing. I hope this isn't the problem.

Attempt 2: Somehow I decided it might be the ATmega16U2 firmware (the smaller chip near the usb port). Download necessary stuff and reflash it. This took a while for me to figure out, but I finally did it. Successful firmware update, but no results. I never found a good tutorial on how to do this on a Mega, so I will post one later based on what I learned next time.

Attempt 3: Re-download Arduino IDE. Yes, this should have been my first step, but for various reasons it was not. Well this did not fix it either, but then a few days ago I notice that there was a new version 1.0.4. The release notes yielded this, "Fixed a bunch of bugs on Mega2560's bootloader (Mark Sproul)." Bingo I think. My problems are solved.

Well to upload the bootloader I needed a programmer. So now I bought what I should have bought in the first place, a usbtinyisp. I got mine off eBay from a US seller for $15 I think. You can also get kits HERE. There's a picture if you're wondering.

I uploaded the bootloader (go HERE for now). I may do a tutorial on this later too. Who knows. Anyway, I upload the bootloader and it appears to go well until I get an error message. It didn't work. However, I notice that the led is blinking on the Arduino. That's odd. Before it was just on all the time. It wouldn't blink even if  I pushed the reset button. I plugged in the USB cable to the Arduino, and its alive again.

I have no idea what the problem was or what fixed it, but it now works again. The moral of this story (for me anyway) is spend the $15 and get an isp. $15 could have saved me many hours. Then again, I learned a lot through this process. I learned a lot about flashing firmware, loading bootloaders, and maintaining patience.

There will be more posts to come now. I hope this helped someone.
Matthew