PlainDSP

plaindsp_audio_kit_s
The huge popularity of PlainDSP (merge of PlainFFT and PlainADC libraries) and the numerous requests for help drove me to think about a convenient solution for all designers, artists, students, professors, R&D people, prototypists who need to understand, experiment, create systems which feature advanced Digital Signal Processing on Arduino. The result of intense thoughts, design and writing is the collection PlainDSP kits, starting with the audio kit.

So please, pay a visit to plaindsp web site. By getting one of these kits you not only get a desirable product you also support a private initiative for popularizing science. Thank you.

 

[HOWTO] PlainDSP audio shield: M2M Communication system

The Critical Tinkers team recently achieved an amazing application based on the plaindsp kit. The M2M protocol they developed provides a smart way to send information to an Arduino board using a plaindsp audio shield from any sound emitting device (e.g. a cell phone). Next video is a teaser which demonstrates the principle of operation, as long as your computer is not muted !

Learn much more about this M2M communication application from plaindsp.com

Stepper Motors (Part 3)

Part 12, 3

A4988 module

Let’s go into the details of this module through the understanding of its pinout:

pololu_3

The suggested basic wiring is as follows:

pololu_4

  • ~ENABLE: GND
  • MS1, 2 & 3: GND
  • ~RESET connected to ~SLEEP
  • STEP: step pulse
  • DIR: rotational direction
  • GND: same GND for VDD and VMOT
  • VDD: 3.3V to 5V
  • 1A,1B: winding 1
  • 2A, 2B: winding 2
  • VMOT: as per stepper motor specifications

Note: the ~ spanish tilde is used for negating a bit value in C ((~0 | 1) == 1); this sign is also used in Ki

Step pulses must simply comply with the required pulse width as per the A4988 datasheet.

pololu_5

The nice thing about this driver is that you do not have to care about the duty cycle of the step pulse signal. On the other hand, care shall be taken about choosing the appropriate frequency so that it fits the stepper motor requirements (Check the “Torque” paragraph in Part 1). There is no danger at all at using innapropriate frequency. If the frequency is too high, the rotor will erratically move or not move at all. If the frequency is too low, the rotor will move in rough steps and generate a growling sound.

Next is a code sample for running the A4988 module in a basic way:

uint8_t _stepPinMask = (1 << PINB5);
uint8_t _dirPinMask = (1 << PINB4);
uint16_t _pulsesPerRound = 48; /* As per the stepper motor specifications */

void setup(void)
{ 
	/* Initialize ports */
	DDRB |= _stepPinMask;
	DDRB |= _dirPinMask;
}


void loop(void)
{
	/* Rotate motor back and forth */
	Rotate(_pulsesPerRound << 1, 1, 5000);
	Rotate(_pulsesPerRound << 1, 0, 5000);
}


void Rotate(uint16_t steps, uint8_t direction, uint16_t pulseWidth) 
{
	if (direction) {
		PORTB |= _dirPinMask;	
	} else {
		PORTB &= ~_dirPinMask;
	}
	for (uint16_t i = 0; i < steps; i++) {
		/* Generate a step pulse. The pulse width is expressed in microseconds  
		The on state is twice the minimum requirement and it is insignificant 
		versus the off time which is mainly responsible for the frequency 
		setting */
		PORTB |= _stepPinMask;
		delayMicroseconds(2);
		PORTB &=  ~_stepPinMask;
		/* Use the most appropriate delay function */
		if (pulseWidth < 16000) {
			delayMicroseconds(pulseWidth);
		} else {
			delay(pulseWidth / 1000);
		}
	}
}

 

Stepper Motors (Part 2)

Part 12, 3

Stepper motor drivers

These electronic devices are the interface between the stepper motor and the controller (e.g. Micro-controller, computer, etc.). Here is a short recap of the expected requirements for such an interface:

  • Drive Unipolar and/or Bipolar motors
  • Convert step commands into appropriate waveforms applied to the motor coils
  • Set direction (cw / ccw)
  • Use separate voltages for digital command and motor supply

In addition to these mandatory requirements, we may enumerate (highly) desirable requirements:

  • Over current protection
  • Over temperature protection
  • Open circuit or short circuit protection
  • Microstepping
  • Low power dissipation

Unipolar or bipolar?

The first decision to be made depends upon the type of stepper motor to be driven. Next pictures illustrate in an other simplified manner the two types of motors and the principle of operation of their related drivers:

Unipolar configuration

The term unipolar means that the current flowing through each winding always goes in the same direction.

g3870

Advantages

  • Simple electronics

Drawbacks

  • More complex wiring, higher cost of motor production
  • Lower motor size/torque ratio, as only 1 coil out of 4 is used for each angle displacement.

Bipolar configuration

In the bipolar configuration, the current flowing through each winding goes in both directions (H-bridges).

g3436

Advantages

  • Simple wiring, lower cost of motor production
  • Better motor size/torque ratio, as 1 coil out of 2 is used for each angle displacement.

Drawbacks

  • Much more complex electronics (H-bridge configuration)

Discrete or integrated design?

Based on the above requirements, the second decision to be made is: shall be build a discrete components based module or use an integrated module? Well, from the point of view of size, efficiency, performances and cost, integrated solutions are the most attractive option. This drove me to scan the available options, including the modules in use in most early 3D printers.

This module is based on the Allegro A4988 chip which is a highly integrated circuit containing all the enumerated requirements in a tiny package.

ET-QFN-with-exposed-pad-28-lead

The component information is available from here and the  data sheet available from here. Multiple implementation of this component exist. The most popular module has been designed by Pololu and it is available from their site

  0J4576.1200

 

The 2 banks of 8 pins make this module easy to plug on a bread board or on most 3D printers or CNC mainboards. From the picture above, we can observe the sub-miniature trim pot used for setting the trip point for triggering an overcurrent condition. These modules are available from many places at variable prices, always below 5€. The few ones that I bought on eBay came assembled in an antistatic package  containing an optional dissipator.

pololu_1

Here is an example of use of the module which is plugged on the breadboard from an arduino proto shield:

pololu_2

In its most simple configuration, the wiring is very simple

bipolar_step_mot

The only additional component is a 100µF capacitor used for filtering transient voltages. the A4988 can also drive unipolar stepper motors as shown below

unipolar_step_mot

Stepper Motors (Part 1)

Part 12, 3

The development and use of stepper motors is directly related to the development of digital electronics. Early systems featuring stepper motors were requiring quite complex electronics made of gates, counters, buffers and voltage interfaces. In the late 70’s I contributed to the automation of a soldering machine for tunnel diode silicon chips. Square silicon chips were picked up from a container placed on a XY tray. Engineers from SESCOSEM had a hard time deciding about the technology to be used for the XY tray drive: analog + indexing system or stepper motor? At this time, the size of the required stepper motors was the main limiting factor. Nowadays they would have probably prefered a stepper motor, such as the very popular NEMA17 series stepper motors in use in many low cost 3D printers

4018_High_Torque_Stepper_P

The aim of this paper is not to describe the principle of operation of stepper motors. Many web sites did that very well before with plenty illustrations and animations. Using your favorite web search engine will inevitably drive you to many interesting places. However, let’s recap the main properties from these special types of motors.

Torque

muscle

This is an indication of how muscled is one motor. In principle, this is the most critical parameter to be taken into account. How much N.m do we need to drive our application? This is quite a complex task which involves lots of calculations and a bit of intuition and experience when addressing the safety margin question. If the objective is just to play around with a stepper motor, any motor will fit. If this motor must drive pretty heavy loads and break friction resistance, torque might become critical.

Note: Stepper motors behave very differently from all other electrical motors, leading to the need for defining torque related terms such as:

  • Holding Torque: amount of torque that the motor produces when it has rated current flowing through the windings but the motor is at rest.
  • Detent Torque: amount of torque that the motor produces when it is not energized. No current is flowing through the windings.
  • Pull-in Torque Curve: Shows the maximum value of torque at given speeds that the motor can start, stop or reverse. The motor cannot start at a speed that is beyond this curve. It also cannot instantly reverse or stop with any accuracy at a point beyond this curve.
  • Stop / Start Region: Area on and underneath the pull-in curve. For any load value in this region, the motor can start, stop, or reverse “instantly” (no ramping required) at the corresponding speed value.
  • Pull-out Torque Curve: Shows the maximum value of torque at given speeds that the motor can generate while running in synchronism. If the motor is run outside of this curve, it will stall.
  • Slew Range: the area between the pull-in and the pull-out curves, where to maintain synchronism, the motor speed must be ramped (adjusted gradually).

Angular resolution

angles

This is an indication of how little can be the angular each single displacement of the shaft. This value is always a fraction of 360′ and it usually ranges from few degrees down to fractions of a degree (e.g. 3.6, 1.8, 0.9, 0.45 degree). Trivial enough, the number of steps per revolution depends on the angular resolution (e.g. a 1.8 angular resolution leads to 200 steps/rev).

Note: Thanks to adequate excitation of winding coils, some stepper motor drivers can set sub resolution angles (1/2, 1/4, 1/8 and 1/16 angle), known as microsteps.

Size

size

Stepper motors exist in many different sizes. However, some standardization exist, such as the NEMA. NEMA 08, 11, 14, 16, 17, 23, 24, 34 42 and 52 stand for the size of the front mounting plate of the motor: 20mm, 28mm, 35mm, 39mm, 42mm, 57mm, 60mm, 86mm, 110mm and 130mm respectively. Then take care about the length of the motor, and also about the diameter and length of the shaft.

Internal wiring

g4030

There are mainly two types of internal wirings easily recognizable thanks to the number of supply leads.

  • Bipolar motors require only 2 pairs of leads.
  • Unipolar motors require 2 times 3 leads.

Note: A driver for bipolar motors will also be able to drive a 6 leads unipolar motor. The only required modification consists is NOT connecting the common connection. On the other hand, a driver for unipolar motors will NOT be able to drive bipolar motors. This subject shall be covered in more details in the next coming posts.

Phase resistance

This is the ohmic value for each winding, it may vary from tens of ohm to tenths of ohm. This resistance must be taken into account when selecting the appropriate driver. Depending upon the supply voltage, the resulting current may vary from hundreds of milliamps to amps. This is real power!

Next post on same subject

Blog of the Day

A robot which helps.

At first glance, this balancing robots looks like “just an other balancing robot”, except that the control is expected to be pretty complex for  “just an other balancing robot”. Watching the attached video almost immediately changed my mind: this robot looks like the ultimate helper for carrying things that you cannot manage on your own for various reasons: too heavy, too large, too fragile, etc.

Read “A Robot That Balances on a Ball”

Watch the video

Tips and Tricks (Part 20)

Previous tip and trick

Acquiring data is great, sending data away is even greater. In this way, all sorts of physical measurements can be remotely read in order to capture events, record signals, trigger alarms, etc.

More and more communication solutions exist, each of them having their advantages and drawbacks. The aim of this post is not to provide an exhaustive list of them. However, let’s mention the most popular devices and protocols from the Arduino planet:

  • Xbee/ZigBee: versatile, pretty low power, from cheap to costly
  • RF12: cheap, low power, limited range and functions
  • GSM/GPRS: almost universal, power greedy, expensive

The Xbee modules have a very particular foot print which features 2x 10 pins with 2mm spaces. Many makers addressed the need for Arduino compatible shields, including the Arduino team it self (Check this thread). This particular shield features a sliding switch which allows the user to manage data exchanged between the Xbee module and the micro controller unit (MCU) or the USB cable.

switch1 switch2

But the principle of sharing Rx Tx lines from Arduino has strong limitations, mainly when you need to upload code to the Arduino board, while the shield and the Xbee module are attached to it.

Here is a very easy (almost trivial) trick which will release some of your stress. The idea is to leave the Rx Tx pins in peace with the MCU while applying no non-reversible changes to the electronics or PCB from the shield. This is how:

Take an Arduino board

UNO

Slightly bend the Rx Tx pins from the shield so that they no longer get into the Arduino board socket

shield_pins

Plug the shield on the Arduino board

assembly_pin_in_a

Place one jumper between Rx pin and digital pin 2 and one jumper between Tx pin and digital pin 3

jumpers1

Instead of using the commands from the Serial library, use the commands from any soft serial library (This one for example) and link the pin 2 and 3 to the receive and send pins.

#include <SoftwareSerial.h> // Include library
SoftwareSerial mySerial(2, 3); // Create object and declare Rx and Tx pins

void setup()  
{
    mySerial.begin(9600); // initialize comm port
}

void loop(void)
{
    mySerial.println("AT"); // Send any instruction to the comm port
    while(true); // Run once
}

That’s all! Under these conditions, the shield will perform as before and blink as it should. In addition, you re now free to use the Serial commands for debugging your application.

HTH

 

LCD direct driving (Part 1)

Part 1

Driving LCD units has been largely documented over internet, arduinoos started investigating this subject with this post.  These units look like the following one:

hex

The disassembled front panel features the following parts:

dissassembly

 

 

And the bottom panel of  the LCD unit features two controllers:

LCD_bottom_tag

These controllers handle the signals from Arduino (or any MCU) and drive the LCD matrix which is composed of two lines of 16 characters. Each character is a 5 by 8 dots matrix as illustrated below:

matrix

So the resulting matrix contains 16 lines and 80 rows. This matrix is driven by the controllers with the wiring is illustrated below:

uc_simplified_schema

For example, the controller’s may be one of KS0066, SPLC780D1 or HD74800. Carefully read the communication protocol related to each of these controllers prior to programming your own code.

 

Now we listed the leading components of an LCD unit, we will focus on only one, the liquid crystal display. The goal of this article is to show how to drive a liquid crystal display directly from Arduino, without any controller or external component. Next is a picture of a bare liquid crystal display:

LCD_3_4

 

For sake of simplicity, we will use a 7 segments display. Unlike the alphanumeric LCD units which have been detailed till now,  a character is displayed using 7 segments instead of using a 5 by 8 dots matrix. For example, displaying a ‘A’ is made as follow:

alphanum_7segments_A

The 7 segments display has 24 pins for driving 3 digits of 7 segments and 2 dots arranged as follows :

LCD_segments

Compared to a 4/8 data pins LCD units, using 24 pins may not be handy but it could be nice to use an LCD display in some use cases, for example:

  • very small packaging
  • very low cost
  • curiosity!

Technically, each pin drives one segment except one pin which is called COM (for common). The datasheet of the LCD display above gives the following segments mapping:

LCD_segs

Each digit has 7 segments called A, B…G. For example, activating the segments B2 and C2 will show a “1” on the center digit. The datasheet provides the following pins mapping:

pin_mapping

Now we know which segment to activate to print something, we will see how to activate a segment. To be set on or off, a liquid crystal segment has to be polarized in one direction, then polarized in the other direction, call it the first and the second pass. Then the segment will keep its state (on or off) for few milliseconds if no voltage difference is applied across it. The voltage applied to a segment is the difference between its associated pin voltage and the COM pin voltage as illustrated below:

unconnected_simplified

Driving an LCD display with Arduino requires the use of the digital pins, they may be:

  • at 0V
  • at 5V
  • left unconnected

Left unconnected ? digitalWrite() does not provide it, huh ? Not directly but the following couple of lines set a pin unconnected (AKA floating or High-Z):

pinMode(pin, INPUT); /* set pin as input */
digitalWrite(pin, LOW); /* set to 0 in input mode */

For sake of simplicity, we will only use the unconnected state for the COM pin as illustrated by the following schema:

unconnected

The following table gives the voltage applied to a segment depending on its pin state and the COM pin state :

COMpinvoltage differenceusage
0V0V0Vturn off a segment (first pass)
+5V+5V0Vturn off a segment (second pass)
0V+5V+5Vturn on a segment (first pass)
+5V0V-5Vturn on a segment (second pass)
unconnected 0V or 5V nohold the last state
In other word, turning a segment off then on is done as follows:

phase

Knowing the theory, displaying a digit can be made in few steps:

  • set each segment data pin according to the  desired text to print
  • set the COM pin low and wait a short period
  • set each segment data pin to the opposite voltage from its previous state
  • set the COM pin high and wait a short period
  • make the COM pin floating

On Arduino, this can be coded as follows:

void Display(uint8_t value)
{ 
/* Set segments data */
uint8_t segments;
segments = vSegments[value];
for (uint8_t i = 0; i < 7; i++) {
digitalWrite(vDataPins[i], (segments & 0x01));
segments >>= 1;
}
/* Common pin state LOW */
pinMode(_comPin, OUTPUT);
digitalWrite(_comPin, LOW);
delay(1);
/* Set segments data */
segments = vSegments[value];
for (uint8_t i = 0; i < 7; i++) {
digitalWrite(vDataPins[i], !(segments & 0x01));
segments >>= 1;
}
/* Common pin state HIGH */
digitalWrite(_comPin, HIGH);
delay(1);
/* Common pin state HIGH-Z */
pinMode(_comPin, INPUT);
digitalWrite(_comPin, LOW);
}

Note: the liquid crystal segments may be damaged if a continuous direct current is applied to them. Take care of not keeping the same voltage across a segment for too long.

Turning on all segments of the third digit except the ‘E’ with Display(0x6F) will display the ‘9’ character as illustrated below:

9

Some LCD displays have several COM inputs to manage more segments with less pins, the next post will show how to handle them.

Blog of the day

“Measure the mass of an eyelash with a DIY microbalance”, an awesome project from electronics-lab.com

electronic-lab.com

Range finder (Part 1)

Part 1

A lot has been said and written about the HC-SR04 range finder so that the aim of this post is not to rewrite the same code sample again and again. The idea here is to get one step forward by looking at this sensor in more details and to try to tidy-up some confusing points;

HC-SR04_pic1

The principle of operation of this sensor is based on the time needed for a sound to travel from a source to a destination sensor. A sound burst is generated by a piezoelectric element. This burst is made of a sine wave at 40 000 Hz. This burst travels in a sound cone of approximately 15° towards the target. As the base of the cone expends with the distance from the burst generator, the surface of the target must be large enough for echoing properly the signal. Next plot illustrates the relationship between the distance of the target and its diameter

plot

Also, while flat surfaces are ideal for reflecting the sound burst, this sound burst may slip on an irregular surface and fail to echo the signal properly. The HC-SR04 makes provision for this type of situation and a timeout prevents the module from waiting and waiting, and waiting the echo.

 Once these parameters taken into account, the module proves to be working fine and is able to accurately measure distances ranging from few centimeters to few meters. The datasheets say 2 cm to 400 cm with a resolution of 3 mm. This distance is calculated from the signal produced by the HC-SR04. It consist in a positive square pulse which rising edge occurs when the module generates the sound burst and falling edge happens when the module reads the echo. Knowing the time needed for sound to travel in free air, it is easy to calculate the distance with the following formula: d = 1/2 * burst_travel_time * speed_of_sound. The travel time is halved as the burst has to travel back and forth.

Often neglected is the real speed of sound. Most publications talk about 340 m/s in free air. In reality, the speed of sound in free air – in other words, in earth’s atmosphere – the main factor affecting the speed of sound is the temperature. Next example shows the difference in distance estimates versus temperature.

At 10°C, a signal duration of 10 ms translates in a distance of 1.68 m, while the same pulse duration at 30°C translate in a distance of 1.75 m. So that the temperature parameter will have to be taken into account for accurate measurements. At 20°C, the speed of sound is 343 m/s.

Exercising the HC-SR04 in excellent conditions (stable temperature, concrete walls used as targets, stable measuring devices), the observed performances of the devices are slightly different. Principally in terms of short distances: 10 cm seems to be the shortest distance that the module can measure accurately. Even with oversampling and averaging techniques, 3 mm resolution looks fully theoretical, and I would not advise to build a critical equipment based on this specification. Talking about a 1 cm resolution sounds more reasonable.

In theory, running the HC-SR04 looks straightforward, and it is really as long as no adverse events contradict its measuring process. The measuring procedure is as follows:

  • Send a positive pulse which duration is at least 10 µs on the trigger pin
  • Just after that wake-up signal, the emitting piezoelectric transducer sends 8 ultrasound bursts and sets the echo line to the HIGH state
  • When the receiving piezoelectric element reads the echoed signal, the echo line is set to LOW state
  • Compute distance based on speed of sound in free air

If the receiving piezoelectric element fails to receive and echo within the next 38 µs, the HC-SR04 will timeout. Also, the datasheet specifies that the cylcle time should not be less than 60 ms.

This procedure looks plain simple, and most (not to say all) code samples match this simple approach by using a digitalWrite() HIGH and LOW, followed by a pulseIn() function with an appropriate timeout. Well the reality is not as plain trivial as we will see in the next posts…