Thursday, May 30, 2013

Stepper Motors and Arduino: 28BYJ-48 with ULN2003

Today I will be exploring the world of stepper motors. I recently purchased a 28BYJ-48 stepper motor with a ULN2003 controller. They are available from a host of vendors for a few dollars and seem to be pretty popular in the Arduino community.

Getting started, there are several links you might find useful.

  • Basic information on the motor and controller as well as a sample sketch using the standard Stepper library.
  • The Stepper Library- This is the library that is included with the Arduino IDE. This library is set up to run a stepper without a gearbox, so it would have to be modified.
  • Stepper2.ino- This sketch includes a full set of functions that can be used to run the 28BYJ-48. It is discussed on THIS page, but it appears that the plans to convert it into a "real" library were never implemented. 
  • Custom Stepper Library- This library can be used to control a variety of steppers, but the default settings are for the 28BYJ-48
First I just wanted to get the stepper turning. I found THIS forum thread with some basic code to get it running. HERE is the code. It is very basic and does work. If you read THESE notes and still didn't understand how steppers work. This sketch might clear it up for you. Below is a video of the sketch working. 

Note how it is wired. You don't want to power the stepper from the Arduino. It can pull 90mA which is a lot for your little Arduino. I used my nifty breadboard power supply that I picked up for a few dollars on Ebay. Power goes to the left 2 male pins on the ULN2003 breakout (marked - + 5-12V). The jumper on the right just switches power to the motor. Removing it opens the circuit between the + power supply and the motor. Other than that, just use some female-female jumpers to connect the inputs to the whatever pins you are using on the Arduino. I am using an Arduino Mega 2560 with an Arduino sensor shield v4, so this is very easy to do. For those that don't know, the ULN2003 is just a little Darlington Array that allows us to switch power from an external source on and off rather than using the Arduino's on board power supply.

Next I decided that I would try the Arduino Stepper library first. While Stepper2 looks promising, I wanted something actively supported. Luckily THIS wiki provides code for using the standard library. HERE it is again, saved for posterity. I will note that 4096 steps resulted in 2 revolutions. Also, at the default steps/revolution 300 appeared to be a good maximum speed. 400 would not run at all. When I changed the steps/revolution to 2048, 10 worked well as a max. Another useful thing to know, the clockwise and counter-clockwise directions are defined when looking at the motor from the back (the side with the label). That is, from the perspective I used in the video above it will be backwards. 

If it is not working try some of the things below. If those don't help, Google the problem. If all else fails, comment, and I will see what I can do.
  • Reduce the speed. These motors only turn so fast before they bind up and stop moving.
  • Check the motor's temperature. The top speed of mine seemed to depend a bit on how warm it was.
  • Check wiring. Make sure your Arduino is hooked up correctly and you have defined the right pins in your code.
  • Check the jumper on the ULN2003 control board. It must be in place (bridging the right two pins).
Well that's about all I have at the moment. I have not dug into the other two stepper libraries I listed. I just wanted to do an intro so I could add stepper motors to my robo-arsenal. If I do any projects with them I will post about it.

-Matthew

Tuesday, May 28, 2013

nRF24L01+ Arduino Communication on Arduino Mega 2560

Disclaimer: Note the last paragraph.

In my quest to explore inter-Arduino communications, I bought 2 nRF24L01+ modules. These are pretty neat radios. From what I have read, they are AM. They can be used with key fob remotes or in a network of up to 6 modules. They are also very cheap. My 2 were $3 on Ebay, but many vendors sell them.

When I first began working with these modules I needed a way to interface with them. Wanting to
breadboard at least one of them, I created the adapter shown to the right. It isn't a perfect solution. The module itself gets in the way of wiring slightly, but my jumpers fit in there good enough.

Next I loaded the RF24 Library. HERE is a blog post by maniacbug that details using the module on an Arduino Uno. It is very useful. THIS page also helped. However, I don't have an Uno. I only have an Arduino Mega 2560. This means that we need to change a few things.

First, we need to change the pins. The Arduino Mega's SPI pins are in different positions than the Arduino Uno. You can figure these out pretty well or you can look below.
          Uno           Mega

  • 11       -      51            (MOSI)
  • 12       -      50            (MISO)
  • 13       -      52            (SCK)
  • 10       -      53            (CSN)
  • 9         -      40 (Your choice) (CE)
Another note, IRQ is not needed for anything I will be discussing. Just leave it unplugged. 

Second, the code needs to be changed slightly.
RF24 radio(9,10);        needs to be changed to      RF24 radio (40, 53);

On the receiving end, I decided to use my Hackduino. Since it is basically an Arduino Uno, the pins are wired the same, and the example code does not need to be changed at all.

However, I did have the problem of needing a 3.3V power supply. Well a few minutes and a Google search later I found THIS calculator and built my first voltage divider circuit. I used a 470 Ohm resistor between 5v and output. 220 and 22 Ohm resistors in series (for a total of 242 Ohms) were placed between output and ground. I read it with a volt meter and it was right on the money, 3v3.
3.3v voltage divider
Black: GND   White: 5v    Green: 3.3v output

Well here goes nothing. Open the serial monitor and type t. I got this screen.

The first part of that is fine. The second is not.

Well I did some digging. While I had found two forum threads (HERE and HERE), I had not found them terribly useful. They came to the conclusion that he Arduino Mega power supply was the problem. While this may be the case, no combination of capadcitors seemed to fix it. I also went on to try the power supply from my Hackduino, 2 AA batteries, and the 3.3V supply on my breadboard power supply. None of these things worked.

I did successfully get it to send once, but I have no idea how. It just worked. I unplugged the USB and plugged it back in, and it didn't work. I have rung out every jumper I am using and have tested all the pins with an LED. I swapped my two RF modules out. Same problems. At this point, I really have no clue what the problem is. I don't have an Arduino other than this one to try it on. I also don't have a variable power supply to test with.

Well that's all I have. I admit that I am quite disappointed with myself for posting an unsuccessful project. I don't know if I will continue working on it or not, but if I do get it working I will post an update. I may try the Mirf library, but we will see. I only paid a few dollars for these modules, and if they are bad I don't want to waste any more time on it. If anyone has any suggestions, feel free to comment. Regardless of my apparent failure, I still learned quite a bit in this endeavor. I hope you have better luck!

-Matthew

Monday, May 20, 2013

Virus Removal: Part 2

Well this is part two, which is unfortunate. As I feared might be the case, we did not get all of the viruses on my relative's computer (see part 1). The next morning after I turned controls back over to my relative, we got a call. Something called Amazon Cloud Drive came up.

Well I can handle this, get in the car and drive over. Turns out Amazon Cloud Drive is not the problem, not even close. Some "mysterious" entity had broken the internet and the sound drivers. More snooping, the Windows Security Service that handles firewalls and such things (I gathered that is what it did) would not launch. Things were going haywire. Well fantastic.

Not having time to deal with it just then I kicked off a virus scan and left. On the way home I made a quick call to my brother. Though it is not his field, he has more experience at virus hunting than I do. He was quite encouraging (NOT). Basically, he suggested the problem was what I had already suspected but had not wanted to concede. He decided it was likely that she had a rootkit.

Well that is bad news. Malwarebytes had "removed" rootkit.0Access the day before, but at this point I felt pretty stupid for believing I had beaten it. His suggestion, reformat the drive with an external program and rebuild the computer from the ground up. "Scorched earth." Right. Well I had not conceded that fully yet.

1. Run Malwarebytes Anti-rootkit BETA. I don't work for them. I promise. I just happened to have seen this feature in the previous days and tried it ( from safe mode). It found a rootkit. I "removed" it. Yeah. Right.

2. Run Bitdefender Rescue CD. Well the Trend Micro rescue disk didn't find it last time, but we'll try it. It booted from Linux and scanned the drive. Interestingly, the internet works when booting from Linux. Yep. Virus.

3. Restore System. After much deliberation it was decided that we should restore the system. This basically resets the computer to an image on a hidden partition of the hard drive. Even if we got the virus, the internet and sound drivers as well as who knows what else were hosed. Yes we probably could fix it, but all she does is use it for email and news. We'll just restore it.

We tried to do this through Windows. No dice. Next, reboot and hit alt-f10 to do it outside of Windows. This took several tries for some reason, but eventually we had success. We did the one that saved her documents. For those that are wondering how long this will take (like we were), it took over an hour.

4. Reboot and reassess  Everything that looks good. Reinstall all the antivirus software. Scan the Backup folder where all her old documents were stored. It found something. Delete that and scan again. Then full system scan.

Now we put the computer back together again and hope for the best. Here's to hoping there is no part 3.

-Matthew