Saturday, July 16, 2016

What is a microstep? - Stepper Motors

A stepper motor is designed to move at one step at a time by energising its coils at the exact right times. When the motor moves like this (1 step at a time) it also moves within its torque specs.

Drivers like the EasyDriver can do microstepping. This is a way to get the motor to make each step smaller, at the expense of torque. In other words, you get more accuracy and smoother turning with less turning force.

This is a very cool trick. It is a bit of a juggling act. The EasyDriver is energising the two coils so finely that it manages to keep the motor in-between its resting positions. That is why when you do microstepping, both the motor and the EasyDriver get so hot, they are working very hard.

You can read about the EadyDriver microstepping modes in the documentation. Look for Q12. I am copying the relevant part here for convenience:

The Easy Driver is able to operate in 1/8th, 1/4, half, and full step (2 phase) modes. These four modes are selected by the logic levels on the MS1 and MS2 input pins. Normally, the pull-up resistors on the Easy Driver hold MS1 and MS2 high, which results in a default setting of 1/8th microstep mode.  You can pull either or both to ground to select the other 3 modes if you want. See the table below (taken from theEasy Driver web site):

Image
For a motor like the common 28BYJ-48, one step is 5.625°​ (specs). With the easy driver, depending on the state of the MS1 and MS2 pins, you can get it to move at 5.625°​/2 (half step), 5.625°​/4 (quarter step) and 5.625°​/8 (eight step). You can control MS1 and MS2 with wires connected to GND or 5V, dip switches, or just connected to the Arduino and control them in your sketch.

To find which wires correspond to a coil, look at the diagram in the datasheet. It will be a bit tedious because of the middle connection, but think about this. When you connect pink and blue with your multimeter, you will get the largest resistance. Only one pair can do this. If you connect pink-red or orange-red, or red-yellow or red-blue, you will get the smallest resistance. Now you can know the red (common wire). And when you connect pink-orange and yellow-blue, you will get the middle resistance. So with a bit of patience and a notebook, you can work out the coils

Enjoy this? Check out Arduino Step By Step

Friday, July 15, 2016

Diffence between Unipolar and bipolar stepper motors

Bipolar motors are generally better than unipolar motors. They have more torque and are more efficient.

However, they are more complicated to drive because they need reverse current.

In terms of construction, bipolar motors have multiple (at least two) independent windings. A wire comes out of each of the winding's ends, so you get two wires per winding.

Unipolar motors also have multiple windings, however in addition to the ends of each winding being connected to wires, the middle is also connected to a third wire.

The absence of this third wire means that bipolar motors are slightly simpler to make.

When it comes to driving these motors, however, the simpler bipolar motor requires a more complex driver. This is because, to precisely control its motion, we need to be able to drive current in each winding in both directions.

On the other hand, in a unipolar motor, we can get away with current that flow only in a single direction. This means that the driver electronics can be made simpler. The tradeoff is that we use only half of each winding coil at a given time, and this translates to lower torque and efficiency.

However today, with easy access to motor drivers like H-bridges, it is easy to drive bipolar motors with alternating current. Unipolar motors advantage of not needing the reverse current is not a big deal anymore.

Thursday, July 14, 2016

PWM and buffer overflow

As you may know, in the Atmega328 that powers the Arduino Uno, several of the pins are capable of Pulse Width Modulation (PWM). These are pins  3, 5, 6, 9, 10, and 11. With PWM, we can approximate analog output programmatically and do things like fade an LED on and off, or control the speed of a motor.

In the Atmega328, the register that is used by the PWM function has a resolution of 8 bits. This gives us a total of 255 possible "analog" output levels. If we attach an LED to a PWM-capable pin, we can drive it to 255 different brightness levels. And if we attach a motor, we can drive it to 255 different speed levels.

We can set a PWM value by using the analogWrite(pin, value) instruction.

So, analogWrite(3, 125) would set the register conrolling pin 3 to value 125. The maximum value is 255, since the PWM register is 8 bits wide (2 in the power of 8 is 255).

What happens if we set analogWrite to a value bigger than 255? Say, 256?

Let's think about this for a minute.

 If the PWM value is 255, the binary version is 11111111 is stored in the PWM register. A connected LED would light up in maximum brightness.

Let's add 1 to the register, and make the PWM value 256. The binary version of 256 is 0000000100000000​ since now we need two bytes to represent this value. But, the Arduino (Atmega) can only fit the first byte in its PWM register. The second byte will overflow and "disappear".

So, what you have stored in the PWM register is ​00000001​. This is decimal "1", which means that your LED is practically turned off.

In other words, analogWrite(3, 1) and analogWrite(3, 256) would have the exact same effect on an LED or a motor.

The lesson to take home is that although you can set the PWM value in analogWrite to any decimal you like, only the first byte of this number will fit in the PWM register. The rest will overflow and disappear.

Sunday, May 1, 2016

Visualizing Music With FFT

This display is a 16x32 neopixel. It is displaying patterns generated by a Processing program doing real-time FFT (Fast Fourier transform). Basically it is visualizing music in the frequency domain using a polar-coordinate particle system.

The hardware makes use of Adafruit 8x8 neopixles, two 5v 10amp supplies, a FadeCandy controller, 16 AWG stranded wire , 20 AWG stranded wire, (2 - Female 2.1x5.5mm DC Power Cable Jack Adapter), and some plastic stand offs.

Friday, April 15, 2016

The Learning Lab Kit on a Shield for Arduino

Received this Learning Lab Kit on a Shield for Arduino from Programming Electronics Academy today and am very pleased.  This shield

The Learning Lab Kit on a Shield for Arduino is meant to help you save time – it basically pre-populates common circuits for you.

Circuits that you might already have learned quite well – like LED, potentiometer, or push buttons.

Instead of searching your shag carpet for the 220 ohm resistor that dropped last week, you simply use the Basic Electronics Arduino Shield – and it connects everything up for you.  No need to breadboard the circuits out.

So when you sit down for 20-30 minutes to practice coding on Arduino – then you spend the majority of the time getting to try new things, and less time repeating something you already know.




I couldn't wait to play with mine today







Want to save some time learning Arduino?
Join the thousands of awesome people to sign up for our 

Sunday, April 10, 2016

NeoPixel 16 Ring Fun

NeoPixels are fun and amazing.  In my project I connected 4 of the AdaFruit NeoPixel - 16 RGBW Leds together.  What caught my attention and curiosity was that you can control each of these RGBW Leds using just one wire.

This feat is accomplished with a very timing-specific protocol. Since the protocol is very sensitive to timing, it requires a real-time microconroller such as an AVR, Arduino, PIC, mbed, etc. It cannot be used with a Linux-based microcomputer or interpreted microcontroller such as the netduino or Basic Stamp.

How the protocol works can be found in the WS2812 data sheet.  For each RGB Led a stream of 24 bits will be sent, 8 bits for each color.  The value of each bit, 1 or 0, is determined by the timing of the square wave.

A logic 0 is represented by a signal that is high for .35 mircorseconds followed by a low of .8 microseconds

A logic 1 is represented by a signal that is high for .7 microseconds followed by a low for  .6 microseconds

So just in the process of updating a 16 LED RGB ring you will be sending 48 bytes of data, 3 bytes for each leds RGB value. Each byte contains a value of 0-255 indicating the value of intensity for that particular color (Red, Green or Blue).

Looking at the diagram above the transmission starts with D1 receiving the first 24 bits.  After that D1 will pass subsequent bits on to D2.  Once D2 receives it's 24 it starts passing subsequent bits onto D3.  Note that this is different than usual shift register operation.  The passing on will continue until the data line is held low for 50 microseconds.  Holding the data line low for 50 microseconds is a reset code indicating next sequence is for the WS2812 to process.



Generating the timing above is no easy feat and requires some very skilled hand-tuned assembly code that issues data to the LED drivers at a specific rate.  Fortunately, Phil Burgess / Paint Your Dragon, wrote a library for Adafruit that allows us mortals to control these beauties.

Below is the code and a video of my setup.  Codebender allows you to peek into the library files by holding down the CTRL key while clicking on the library header file.  In this case you would hold the CTRL key and click on "Adafruit_NeoPixel.h".  This will open a new tab with the NeoPixel library and related files.  From there look on the left hand side and select the Adafruit_NeoPixel.cpp file to explore and learn more about this awesome library.

Don't be afraid  If you have any questions please feel free to ask.



Want to save some time learning Arduino?
Join the thousands of awesome people to sign up for our 

Friday, April 8, 2016

Logging Environmental Data and Charting it with Google Charts

Today I have been experimenting with the Particle Photon and logging environment data to the internet via the Data.SparkFun.com.   Data.SparkFun.com is a free service for posting, storing, and reading sets of data. It’s powered by Phant, an open-source, Node.js-based tool that can be run on any server or computer.

Once the data data feed has some data  I can start charting it using a number of free services. Following Sparkfuns tutorial I am using Googles Charts to graph live data on my web site. Adding a barometric sensor to this wouldn't be hard and would make for some interesting weather studies.


Sparkfun Tutorial

Graphing Live Data With Google Charts Tutorial

Sample Live Chart, updated every 60 seconds, from my experiment

 I'll have this data logger along with a neopixel demo and other presentations on display at our Programming Electronics with Arduino meetup this Saturday 




Want to save some time learning Arduino?
Join the thousands of awesome people to sign up for our