In this review we examine an interesting, fun and possibly a prankster’s delight – the “Defusable Clock Kit” from nootropic design. The purpose of this kit is to construct a clock that counts down in a similar method to “movie-style” bombs, and it has terminals to connect four wires to the board. When the countdown timer is beeping away, you need to choose which wire to cut otherwise the “bomb” (alarm) goes off.

Furthermore, it also functions as a normal clock with an alarm, so you can use it daily normal activities. And finally it is based on the Arduino system which allows the kit to be reprogrammed at a later date. Now let’s move forward by examining kit construction.

Packaging

The kit arrives in a re-sealable antistatic pouch that can be reused without any effort:

Assembly

Detailed instructions can be found on the product website. The kit has a very clear and well-detailed silk screen on the PCB:

All the parts required are included, as well as an IC socket for the microcontroller:

Moving forward, the first parts to solder in are the resistors:

… then to the other lower-profile components:

… and the rest:

Which leaves us with the final product:

The clock is designed around simple Arduino-compatible circuitry, so if you wish to alter the firmware for the clock or upload your own sketch, you will need to fit the six-way header pins (in order to connect a USB-FTDI cable). As the pins are horizontal and tend to fall over, it’s easier to solder the first pin from the top of the PCB to hold it in place:

… then turn the PCB over and solder the rest.

Operation

Power is supplied via the DC socket on the PCB, and converted to 5V with a typical 7805 regulator. Therefore your input voltage can range between normal levels of 9~12VDC. Once the power is connected you can set the time for the clock and alarm for normal use. However if you feel like some sweat-inducing excitement, connect four wires each between the terminal blocks at the top of the PCB. Then press the red button to start the ten-second countdown. You can also increase or decrease the countdown time.

Your chances of defusing it in time can be quite low – by cutting one wire you can defuse it, by cutting two other wires nothing will happen and the clock keeps ticking – and by cutting the final wire… well, it’s all over. The wires are randomly chosen each time so you can’t predict which will be the correct wire. (Unless you change the firmware). Now let’s see the clock in action:

At this juncture it would be appropriate to warn the users of this kit not to … well, misuse the clock. To be honest I’m surprised such a kit originated from the US in the first place, but then again it never hurts to have a sense of humour. But seriously, to the untrained eye or casual security guard – this kit will look pretty damn real. So no making any mock explosive models with Play-Doh or metal cylinders and leaving them on the train or bus or under someone’s toilet seat. Then again, that would be good for a laugh – so please keep it at home, not in the railway station.

Further expansion

As mentioned earlier this kit is Arduino (Duemilanove) compatible, you can upload new sketches using a 5V FTDI cable or swapping the microcontroller over in another Arduino-style board. You have four LEDs, a 4-digit 7-segment LED module, a buzzer, and four digital I/O pins via the terminal block on the top-right of the PCB which could control external devices. Furthermore you can download and examine the clock sketch to modify or deconstruct it to determine the operation.

Conclusion

Apart from the laughs and possible mayhem you could cause with this, the kit is easy to assemble and works as described. It would make a great present to get someone interested in electronics, or help them with soldering practice. Furthermore it is certainly unique, and would be fun at parties and other events. High-resolution images available on flickr.

To order your own nootropic design defusable clock kit, head over to tronixlabs.com – offering a growing range and Australia’s best value for supported hobbyist electronics from adafruit, DFRobot, Freetronics, Seeed Studio and much more.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column, or join our forum – dedicated to the projects and related items on this website.

In this article we will examine yet another product from a bundle sent for review by Snootlab, a Toulouse, France-based company that in their own words:

… designs and develops electronic products with an Open Hardware and Open Source approach. We are particularly specialized in the design of new shields for Arduino. The products we create are licensed under CC BY-SA v3.0 (as shown in documents associated with each of our creations). In accordance with the principles of the definition of Open Source Hardware (OSHW), we have signed it the 10th February 2011. We wish to contribute to the development of the ecosystem of “do it yourself” through original designs of products, uses and events.

Furthermore, all of their products are RoHS compliant and as part of the Open Hardware commitment, all the design files are available from the Snootlab website.

The subject of the review is the Snootlab Rotoshield – a motor-driver shield for our Arduino systems. Using a pair of L293 half-bridge motor driver ICs, you can control four DC motors with 256 levels of speed, or two stepper motors. However this is more than just a simple motor-driver shield… The PCB has four bi-colour LEDs, used to indicate the direction of each DC motor; there is a MAX7313 IC which offers another eight PWM output lines; and the board can accept external power up to 18V, or (like other Snootlab shields) draw power from a PC ATX power supply line.

However as this is a kit, let’s follow construction, then explore how the Rotoshield could possibly be used. [You can also purchase the shield fully assembled – but what fun would that be?] Assembly was relatively easy, and you can download instructions and the schematic files in English. As always, the kit arrives in a reusable ESD bag:

There are some SMD components, and thankfully they are pre-soldered to the board. These include the SMD LEDs, some random passives and the MAX7313:

Thankfully the silk-screen is well noted with component numbers and so on:

All the required parts are included, including stackable headers and IC sockets:

It is nice to not see any of the old-style ceramic capacitors. The people at Snootlab share my enthusiasm for quality components. The assembly process is pretty simple, just start with the smaller parts such as capacitors:

… then work outwards with the sockets and terminals:

… then continue on with the larger, bulkier components. My favourite flexible hand was used to hold the electrolytics in place:

… followed with the rest, leaving us with one Rotoshield:

If you want to use the 12V power line from the ATX socket, don’t forget to bridge the PCB pads between R7 and the AREF pin. The next thing to do is download and install the snooter library to allow control of the Rotoshield in your sketches. There are many examples included with the library that you can examine, just select File > Examples > snootor in the Arduino IDE to select an example. Function definitions are available in the readme.txt file included in the library download.

[Update]

After acquiring a tank chassis with two DC motors, it was time to fire up the Rotoshield and get it to work. From a hardware perspective is was quite simple – the two motors were connected to the M1 and M2 terminal blocks, and a 6V battery pack to the external power terminal block on the shield. The Arduino underneath is powered by a separate PP3 9V battery.

In the following sketch I have created four functions – goForward(), goBackward(), rotateLeft() and rotateRight(). The parameter is the amount of time in milliseconds to operate for. The speed of the motore is set using the Mx.setSpeed() function in void Setup(). Although the speed range is from zero to 255, this is PWM so the motors don’t respond that well until around 128. So have just set them to full speed. Here is the demonstration sketch:

Arduino

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

#include <Wire.h>

#include <snootor.h>

SnootorDCM1;

SnootorDCM2;

voidsetup()

{

Wire.begin();

M1.init(2);

M2.init(1);

M1.setSpeed(255);

M2.setSpeed(255);

SC.dump();

}

voidgoForward(intduration)

// move forward for 'duration' milliseconds

{

M1.run(FORWARD);

M2.run(FORWARD);

SC.delay(duration);// in milliseconds

M1.stop();

M2.stop();

M1.run(RELEASE);

M2.run(RELEASE);

}

voidgoBackward(intduration)

// move backward for 'duration' milliseconds

{

M1.run(BACKWARD);

M2.run(BACKWARD);

SC.delay(duration);// in milliseconds

M1.stop();

M2.stop();

M1.run(RELEASE);

M2.run(RELEASE);

}

voidrotateLeft(intduration)

// rotate anti-clockwise for 'duration' milliseconds

{

M1.run(BACKWARD);

M2.run(FORWARD);

SC.delay(duration);// in milliseconds

M1.stop();

M2.stop();

M1.run(RELEASE);

M2.run(RELEASE);

}

voidrotateRight(intduration)

// rotate clockwise for 'duration' milliseconds

{

M1.run(FORWARD);

M2.run(BACKWARD);

SC.delay(duration);// in milliseconds

M1.stop();

M2.stop();

M1.run(RELEASE);

M2.run(RELEASE);

}

voidloop()

{

goForward(2000);

rotateLeft(1000);

goForward(2000);

rotateRight(1000);

goBackward(2000);

rotateLeft(1000);

goBackward(2000);

rotateRight(1000);

delay(2000);

}

… and the resulting video:

For support, visit the Snootlab website and customer forum in French (use Google Translate). However as noted previously the team at Snootlab converse in excellent English and have been easy to contact via email if you have any questions. Snootlab products including the Snootlab Rotoshieldare available directly from their website. High-resolution images available on flickr.

As always, thank you for reading and I look forward to your comments and so on. Furthermore, don’t be shy in pointing out errors or places that could use improvement. Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts, follow on twitter, facebook, or join our Google Group.

[Disclaimer – the products reviewed in this article are promotional considerations made available by Snootlab]

In this article we investigate controlling the NXP (formerly Philips) SAA1064 4-digit LED display driver IC with Arduino and the I2C bus interface. If you are not familiar with using the I2C bus, please read my tutorials (parts one and two) before moving on. Although the SAA1064 is not the newest on the market, it is still popular, quite inexpensive and easy to source. Furthermore as it is controlled over the I2C bus – you don’t waste any digital I/O pins on your Arduino, and you can also operate up to four SAA1064s at once (allowing 16 digits!). Finally, it has a constant-current output – keeping all the segments of your LED display at a constant brightness (which is also adjustable). So let’s get started…

Here is an example of the SAA1064 in SOIC surface mount packaging:

It measures around 15mm in length. For use in a solderless breadboard, I have soldered the IC onto a through-hole adaptor:

The SAA1064 is also available in a regular through-hole DIP package. At this point, please download the data sheet (.pdf) as you will need to refer to it during the article. Next, our LED display examples. We need common-anode displays, and for this article we use two Agilent HDSP521G two-digit modules (data sheet [.pdf]) as shown below:

For the uninitiated – a common anode display has all the segments’ anodes connected together, with the cathodes terminated separately. For example, our LED displays are wired as such:

Notice the anodes for the left digit are pin 14, and the right digit pin 13. A device that is connected to all the cathodes (e.g. our SAA1064) will control the current flow through each element – thereby turning each segment on (and controlling the brightness) or off. Our SAA1064 is known as a current-sink as the current flows through the LED, and then sinks into the IC.

Now, let’s get it connected. There is an excellent demonstration circuit on page twelve of the data sheet that we will follow for our demonstrations:

It looks pretty straight-forward, and it is. The two transistors are standard NPN-type, such as PN2222. The two transistors are used to each turn on or off a pair of digits – as the IC can only drive digits 1+3 or 2+4 together. (When presented in real life the digits are numbered 4-3-2-1). So the pairs are alternatively turned on and off at a rapid rate, which is controlled by the capacitor between pin 2 and GND. The recommended value is 2.7 nF. At the time of writing, I didn’t have that value in stock, so chose a 3.3 nF instead. However due to the tolerance of the ceramic capacitor it was actually measured to be 2.93 nF:

So close enough to 2.7 nF will be OK. The other capacitor shown between pins 12 and 13 is a standard 0.1 uF smoothing capacitor. Pin 1 on the SAA1064 is used to determine the I2C bus address – for our example we have connected it straight to GND (no resistors at all) resulting in an address of 0x70. See the bottom page five of the data sheet for other address options. Power for the circuit can be taken from your Arduino’s 5V pin – and don’t forget to connect the circuit GND to Arduino GND. You will also use 4.7k ohm pull-up resistors on the SDA and SCL lines of the I2C bus.

The last piece of the schematic puzzle is how to connect the cathodes of the LED displays to the SAA1064. Display pins 14 and 13 are the common anodes of the digits.

Once your connections have been made, you could end up with spaghetti junction like this…

Now it is time to consider the Arduino sketch to control out SAA1064. Each write request to the SAA1064 requires several bytes. We either send a control command (to alter some of the SAA1064 parameters such as display brightness) or a display command (actually display numbers). For our example sketches the I2C bus address “0x70 >> 1” is stored in the byte variable saa1064. First of all, let’s look at sending commands, as this is always done first in a sketch to initiate the SAA1064 before sending it data.

As always, we send the address down the I2C bus to awaken the SAA1064 using

Arduino

1

Wire.beginTransmission(saa1064);

Then the next byte is the instruction byte. If we send zero:

Arduino

1

Wire.write(B00000000);

… the IC expects the next byte down the bus to be the command byte. And finally our command byte:

Arduino

1

Wire.write(B01000111);

The control bits are described on page six of the data sheet. However – for four-digit operation bits 0, 1 and 2 should be 1; bit 3 should be 0; and bits 4~6 determine the amount of current allowed to flow through the LED segments. Note that they are cumulative, so if you set bits 5 and 6 to 1 – 18 mA of current will flow. We will demonstrate this in detail later on.

Next, to send actual numbers to be displayed is slightly different. Note that the digits are numbered (from left to right) 4 3 2 1. Again, we first send the address down the I2C bus to awaken the SAA1064 using

Arduino

1

Wire.beginTransmission(saa1064);

Then the next byte is the instruction byte. If we send 1, the next byte of data will represent digit 1. If that follows with another byte, it will represent digit 2. And so on. So to send data to digit 1, send

Arduino

1

Wire.write(B00000001);

Although sending binary helps with the explanation, you can send decimal equivalents. Next, we send a byte for each digit (from right to left). Each bit in the byte represents a single LED element of the digit as well as the decimal point. Note how the elements are labelled (using A~G and DP) in the following image:

The digit bytes describe which digit elements to turn on or off. The bytes are described as such: Bpgfedcba. (p is the decimal point). So if you wanted to display the number 7, you would send B00000111 – as this would turn on elements a, b and c. To add the decimal point with 7 you would send B10000111. You can also send the byte as a decimal number. So to send the digit 7 as a decimal, you would send 7 – as 00000111 in base-10 is 7. To include the decimal point, send 135 – as 100000111 in base-10 is 135. Easy! You can also create other characters such as A~F for hexadecimal. In fact let’s do that now in the following example sketch:

Wire.write(1);// instruction byte - first digit to control is 1 (right hand side)

Wire.write(digits[z]);// digit 1 (RHS)

Wire.write(digits[z]);// digit 2

Wire.write(digits[z]);// digit 3

Wire.write(digits[z]);// digit 4 (LHS)

Wire.endTransmission();

delay(500);

}

// now repeat but with decimal point

for(intz=0;z<16;z++)

{

Wire.beginTransmission(saa1064);

Wire.write(1);// instruction byte - first digit to control is 1 (right hand side)

Wire.write(digits[z]+128);// digit 1 (RHS)

Wire.write(digits[z]+128);// digit 2

Wire.write(digits[z]+128);// digit 3

Wire.write(digits[z]+128);// digit 4 (LHS)

Wire.endTransmission();

delay(500);

}

}

voidclearDisplay()

// clears all digits

{

Wire.beginTransmission(saa1064);

Wire.write(1);// instruction byte - first digit to control is 1 (right hand side)

Wire.write(0);// digit 1 (RHS)

Wire.write(0);// digit 2

Wire.write(0);// digit 3

Wire.write(0);// digit 4 (LHS)

Wire.endTransmission();

}

voidloop()

{

displayDigits();

clearDisplay();

delay(1000);

}

/* **** We bitshift the address as the SAA1064 doesn't have the address 0x70 (ADR pin

to GND) but 0x38 and Arduino uses 7-bit addresses- so 8-bit addresses have to

be shifted to the right one bit. Thanks to Malcolm Cox */

In the function initDisplay() you can see an example of using the instruction then the control byte. In the function clearDisplay() you can see the simplest form of sending digits to the display – we send 0 for each digit to turn off all elements in each digit. The bytes that define the digits 0~9 and A~F are stored in the array digits[]. For example, the digit zero is 63 in decimal, which is B00111111 in binary – which turns on elements a,b,c,d,e and f. Finally, notice the second loop in displayDigits() – 128 is added to each digit value to turn on the decimal point. Before moving on, let’s see it in action:

Our next example revisits the instruction and control byte – we change the brightness of the digits by setting bits 4~6 in the control byte. Each level of brightness is separated into a separate function, and should be self-explanatory. Here is the sketch:

Wire.write(0);// instruction byte - Zero means the next byte is the control byte

Wire.write(B01001111);// set current and bit 3 to 1 for all segments on

Wire.endTransmission();

// now loop through the brightness levels

do

{

init3ma();

delay(d);

init6ma();

delay(d);

init9ma();

delay(d);

init12ma();

delay(d);

init18ma();

delay(d);

init21ma();

delay(d);

}

while(1>0);

}

And again, see it in action:

For our final example, there is a function displayInteger(a,b) which can be used to easily display numbers from 0~9999 on the 4-digit display. The parameter a is the number to display, and b is the leading-zero control – zero – off, one – on. The function does some maths on the integet to display and separates the digits for each column, then sends them to the SAA1064 in reverse order. By now you should be able to understand the following sketch:

So there you have it – another useful IC that can be used in conjunction with our Arduino systems to make life easier and reduce the required digital output pins.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.

In this article we will examine another product from a bundle sent for review by Snootlab, a Toulouse, France-based company that in their own words:

… designs and develops electronic products with an Open Hardware and Open Source approach. We are particularly specialized in the design of new shields for Arduino. The products we create are licensed under CC BY-SA v3.0 (as shown in documents associated with each of our creations). In accordance with the principles of the definition of Open Source Hardware (OSHW), we have signed it the 10th February 2011. We wish to contribute to the development of the ecosystem of “do it yourself” through original designs of products, uses and events.

Furthermore, all of their products are RoHS compliant and as part of the Open Hardware commitment, all the design files are available from the Snootlab website.

The subject of the review is the Snootlab Mémoire – an SD card data logging shield with on-board DS1307 real time clock [and matching backup battery] and prototyping area. It uses the standard SdFat library to write to normal SD memory cards formatted in FAT16 or FAT32. You can download the library from here. The real time clock IC is an easy to use I2C-interface model, and I have documented its use in great detail in this tutorial.

Once again, shield assembly is simple and quite straightforward. You can download an illustrated assembly guide from here, however it is in French. But everything you need to know is laid out on the PCB silk-screen, or the last page of the instructions. The it arrives in a reusable ESD bag:

… and all the required parts are included – including an IC socket and the RTC backup battery:

… the PCB is thick, with a very detailed silk-screen. Furthermore, it arrives with the SD card and 3.3V LDO (underneath) already pre-soldered – a nice touch:

The order of soldering the components is generally a subjective decision, and in this case I started with the resistors:

… and then worked my way out, but not fitting the battery nor IC until last. Intrestingly, the instructions require the crystal to be tacked down with some solder onto the PCB. Frankly I didn’t think it would withstand the temperature, however it did and all is well:

Which leaves us with a fully-assembled Mémoireshield ready for action:

Please note that a memory card is not included with the kit. If you are following along with your own Mémoire, the first thing to do after inserting the battery, IC and shield into your Arduino board and run some tests to ensure all is well. First thing is to test the DS1307 real-time clock IC. You can use the following sketch from chapter seven of my Arduino tutorial series:

Serial.print(hour,DEC);// convert the byte variable to a decimal number when being displayed

Serial.print(":");

if(minute<10)

{

Serial.print("0");

}

Serial.print(minute,DEC);

Serial.print(":");

if(second<10)

{

Serial.print("0");

}

Serial.print(second,DEC);

Serial.print(" ");

Serial.print(dayOfMonth,DEC);

Serial.print("/");

Serial.print(month,DEC);

Serial.print("/");

Serial.print(year,DEC);

Serial.print(" Day of week:");

switch(dayOfWeek){

case1:

Serial.println("Sunday");

break;

case2:

Serial.println("Monday");

break;

case3:

Serial.println("Tuesday");

break;

case4:

Serial.println("Wednesday");

break;

case5:

Serial.println("Thursday");

break;

case6:

Serial.println("Friday");

break;

case7:

Serial.println("Saturday");

break;

}

// Serial.println(dayOfWeek, DEC);

delay(1000);

}

If you are unsure about using I2C, please review my tutorial which can be found here. Don’t forget to update the time and date data in void setup(), and also comment out the setDateDS1307() function and upload the sketch a second time. The sketch output will be found on the serial monitor box – such as:

Those of you familiar with the DS1307 RTC IC know that it can generate a nice 1 Hz pulse. To take advantage of this the SQW pin has an access hole on the PCB, beetween R10 and pin 8 of the IC:

For instruction on how to activate the SQW output, please visit the last section of this tutorial.

The next test is the SD card section of the shield. If you have not already done so, download and install the SdFat libary. Then, in the Arduino IDE, select File > Examples > SdFat > SdFatInfo. Insert the formatted (FAT16/32) SD card into the shield, upload the sketch, then open the serial monitor. You should be presented with something like this:

As you can see the sketch has returned various data about the SD card. Finally, let’s log some data. You can deconstruct the excellent example that comes with the SdFat library titled SdFatAnalogLogger (select File > Examples > SdFat > SdFatAnalogLogger). Using the functions:

Arduino

1

2

file.print();

file.println();

you can “write” to the SD card in the same way as you would the serial output (that is, the serial monitor).

If you have reached this far without any errors – Congratulations! You’re ready to log. If not, remove the battery, SD card and IC from your shield (you used the IC socket, didn’t you?). Check the polarised components are in correctly, double-check your soldering and then reinsert the IC, shield and battery and try again. If that fails, support is available on the Snootlab website, and there is also a customer forum in French (use Google Translate). However as noted previously the team at Snootlab converse in excellent English and have been easy to contact via email if you have any questions. Stay tuned for the final Snootlab product review.

As always, thank you for reading and I look forward to your comments and so on. Furthermore, don’t be shy in pointing out errors or places that could use improvement. Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts, follow on twitter, facebook, or join our Google Group.

[Disclaimer – the products reviewed in this article are promotional considerations made available by Snootlab]

In this article we will examine a variety of products received for review from Gravitech in the United States – the company that designed and build the Arduino Nano. We have a Nano and some very interesting additional modules to have a look at.

So let’s start out review with the Arduino Nano. What is a Nano? A very, very small version of our Arduino Duemilanove boards. It contains the same microcontroller (ATmega328) but in SMD form; has all the I/O pins (plus two extra analogue inputs); and still has a USB interface via the FT232 chip. But more on that later. Nanos arrive in reusable ESD packaging which is useful for storage when not in use:

Patriotic Americans should note that the Nano line is made in the USA. Furthermore, here is a video clip of Nanos being made:

For those who were unsure about the size of the Nano, consider the following images:

You can easily see all the pin labels and compare them to your Duemilanove or Uno board. There is also a tiny reset button, the usual LEDs, and the in circuit software programmer pins. So you don’t miss out on anything by going to a Nano. When you flip the board over, the rest of the circuitry is revealed, including the FTDI USB>serial converter IC:

Those of you familiar with Arduino systems should immediately recognise the benefit of the Nano – especially for short-run prototype production. The reduction in size really is quite large. In the following image, I have traced the outline of an Arduino Uno and placed the Nano inside for comparison:

So tiny… the board measures 43.1mm (1.7″) by 17.8mm (0.7″). The pins on this example were pre-soldered – and are spaced at standard 2.54mm (0.1″) intervals – perfect for breadboarding or designing into your own PCB – however you can purchase a Nano without the pins to suit your own mounting purposes. The Nano meets all the specifications of the standard Arduino Duemilanove-style boards, except naturally the physical dimensions.

Power can be supplied to the Nano via the USB cable; feeding 5V directly into the 5V pin, or 7~12 (20 max, not recommended) into the Vin pin. You can only draw 3.3V at up to 50 mA when the Nano is running on USB power, as the 3.3V is sourced from the FTDI USB>serial IC. And the digital I/O pins still allow a current draw up to 40 mA each. From a software perspective you will not have any problems, as the Nano falls under the same board classification as the (for example) Arduino Duemilanove:

Therefore one could take advantage of all the Arduino fun and games – except for the full-size shields. But as you will read soon, Gravitech have got us covered on that front. If the Arduino system is new to you, why not consider following my series of tutorials? They can be found here. In the meanwhile, to put the size into perspective – here is a short video of a Nano blinking some LEDs!

Now back to business. As the Nano does not use standard Arduino shields, the team at Gravitech have got us covered with a range of equivalent shields to enable all sorts of activities. The first of this is their Ethernet and microSD card add-on module:

and the underside:

Again this is designed for breadboarding, or you could most likely remove the pins if necessary. The microSD socket is connected as expected via the SPI bus, and is fully compatible with the default Arduino SD library. As shown in the following image the Nano can slot directly into the ethernet add-in module:

The Ethernet board requires an external power supply, from 7 to 12 volts DC. The controller chip is the usual Wiznet 5100 model, and therefore the Ethernet board is fully compatible with the default Ethernet Arduino library. We tested it with the example web server sketch provided with the Arduino IDE and it all just worked.

Using this module allows control of two DC motors with up to two amps of current each via pulse-width modulation. Furthermore, there is a current feedback circuit for each motor so you measure the motor load and adjust power output – interesting. So a motorised device could sense when it was working too hard and ease back a little (like me on a Saturday). All this is made possible by the use of the common L298 dual full-bridge motor driver IC. This is quite a common motor driver IC and is easy to implement in your sketches. The use of this module and the Nano will help reduce the size of any robotics or motorised project. Stay tuned for use of this board in future articles.

Next in this veritable cornucopia of add-on modules is the USBHOST board:

turning it over …

Using the Maxim MAX3421E host controller IC you can interface with all sorts of devices via USB, as well as work with the new Android ADK. The module will require an external power supply of between 7 and 12 volts DC, with enough current to deal with the board, a Nano and the USB device under control – one amp should be more than sufficient. I will be honest and note that USB and Arduino is completely new to me, however it is somewhat fascinating and I intend to write more about using this module in the near future. In the meanwhile, many examples can be found here.

For a change of scene there is also a group of Xbee wireless communication modules, starting with the Xbee add-on module:

The Xbee itself is not included, only shown for a size comparison. Turning the module over:

It is nice to see a clearly-labelled silk screen on the PCB. If you are unfamiliar with using the Xbee wireless modules for data communication, you may find my introductory tutorial of interest. Furthermore, all of the Gravitech Nano modules are fully software compatible with my tutorial examples, so getting started will be a breeze. Naturally Gravitech also produce an Xbee USB interface board, to enable PC communication over your wireless modules:

Again, note that the Xbee itself is not included, however they can be supplied by Gravitech. Turning the board over reveals another highly-detailed silk screen:

All of the Gravitech Xbee modules support both series 1.0 and 2.5 Xbees, in both standard and professional variants. The USB module also supports the X-CTU configuration software from Digi.

The MP3 board is designed around the VS1053B MP3 decoder IC. It can also decode Ogg Vorbis, AAC, WMA and MID files. There is a 3.5mm stereo output socket to connect headphones and so on. As expected, the microSD card runs from the SPI pins, however SS is pin 4. Although it may be tempting to use this to make a home-brew MP3 player, other uses could include: recorded voice messages for PA systems such as fire alarm notices, adding sound effects to various projects or amusement machines, or whatever else you can come up with.

The Arduino Nano and related boards really are tiny, fully compatible with their larger brethren, and will prove very useful. Although this article was an introductory review, stay tuned for further projects and articles that will make use of the Nano and other boards. If you have any questions or enquiries please direct them to Gravitech via their contact page. Gravitech products including the Arduino Nano family are available directly from their website or these distributors.

As always, thank you for reading and I look forward to your comments and so on. Furthermore, don’t be shy in pointing out errors or places that could use improvement. Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts, follow on twitter, facebook, or join our Google Group.

[Disclaimer – the products reviewed in this article are promotional considerations made available by Gravitech]

In this article we introduce the inexpensive thermal printer that has recently become widely available from Sparkfun and their resellers. The goal of the article is to be as simple as possible so you can get started without any problems or confusion. In the past getting data from our Arduino to a paper form would either have meant logging it to an SD card then using a PC to finish the job, or perhaps viewing said data on an LCD then writing it down. Not any more – with the use of this cheap and simple serial printer. Before we get started, here is a short demonstration video of it in action:

Not bad at all considering the price. Let’s have a look in more detail. Here is the printer and two matching rolls of thermal paper:

… and the inside of the unit:

Loading paper is quite simple, just drop the roll in with the end of the paper facing away from you, pull it out further than the top of the front lip, then close the lid. The paper rolls required need to be 57mm wide and have a diameter of no more than 39mm. For example. There is a piece of white cardboard stuck to the front – this is an economical cover that hides some of the internals. Nothing of interest for us in there. The button next to the LED on the left is for paper advance, and the LED can blink out the printer status.

From a hardware perspective wiring is also very simple. Looking at the base of the printer:

… there are two connections. On the left is DC power, and data on the right. Thankfully the leads are included with the printer and have the plugs already fitted – a great time saver. You may also want to fit your own rubber feet to stop the printer rocking about.

Please note – you need an external power supply with a voltage of between 5 and 9 volts DC that can deliver up to 1.5 amps of current. When idling the printer draws less than 10 milliamps, but when printing it peaks at around 1.47 A. So don’t try and run it from your Arduino board. However the data lines are easy, as the printer has a serial interface we only need to connect printer RX to Arduino digital 3, and printer TX to Arduino digital 2, and GND to … GND! We will use a virtual serial port on pins 2 and 3 as 0 and 1 will be taken for use with the serial monitor window for debugging and possible control purposes.

If you want to quickly test your printer – connect it to the power, drop in some paper, hold down the feed button and turn on the power. It will quickly produce a test print.

Next we need to understand how to control the printer in our sketches. Consider this very simple sketch:

Arduino

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

/*

Example 38.1 - Sparkfun Thermal Printer Test (COM-10438)

http://tronixstuff.com/tutorials > chapter 38

Based on code by Nathan Seidle of Spark Fun Electronics 2011

*/

#include <SoftwareSerial.h>

SoftwareSerialThermal(2,3);

intheatTime=80;

intheatInterval=255;

charprintDensity=15;

charprintBreakTime=15;

voidsetup()

{

Serial.begin(57600);// for debug info to serial monitor

Thermal.begin(19200);// to write to our new printer

initPrinter();

}

voidinitPrinter()

{

//Modify the print speed and heat

Thermal.write(27);

Thermal.write(55);

Thermal.write(7);//Default 64 dots = 8*('7'+1)

Thermal.write(heatTime);//Default 80 or 800us

Thermal.write(heatInterval);//Default 2 or 20us

//Modify the print density and timeout

Thermal.write(18);

Thermal.write(35);

intprintSetting=(printDensity<<4)|printBreakTime;

Thermal.write(printSetting);//Combination of printDensity and printBreakTime

Serial.println();

Serial.println("Printer ready");

}

voidloop()

{

Thermal.println(" Visit http://tronixstuff.com ");

Thermal.write(10);//Sends the LF to the printer, advances the paper

Thermal.print(" Millis = ");

Thermal.println(millis());

Thermal.write(10);

Thermal.write(10);

do{}while(1>0);

}

After ensuring your printer is connected as described earlier, and has the appropriate power supply and paper – uploading the sketch will result in the following:

Now that the initial burst of printing excitement has passed, let’s look at the sketch and see how it all works. The first part:

configures the virtual serial port and creates an instance for us to refer to when writing to the printer. Next, four variables are defined. These hold parameters used for configuring the printer. As the printer works with these settings there is no need to alter them, however if you are feeling experimental nothing is stopping you. Next we have the function initPrinter(). This sets a lot of parameters for the printer to ready itself for work. We call initPrinter() only once – in void setup(); For now we can be satisfied that it ‘just works’.

Now time for action – void loop(). Writing text to the printer is as simple as:

Arduino

1

Thermal.print("text");

You can also use .println to advance along to the next line. Generally this is the same as writing to the serial monitor with Serial.println() etc. So nothing new there. Each line of text can be up to thirty-two characters in length.

The next thing to concern ourselves with is sending commands to the printer. You may have noticed the line

Arduino

1

Thermal.write(10);

This sends the command to advance to the next line (in the old days we would say ‘carriage return and line feed’). There are many commands available to do various things. At this point you will need to refer to the somewhat amusing user manual.pdf. Open it up and have a look at section 5.2.1 on page ten. Notice how each command has an ASCII, decimal and hexadecimal equivalent? We will use the decimal command values. So to send them, just use:

Arduino

1

Thermal.write(value);

Easy. If the command has two or more values (for example, to turn the printer offline [page 11] ) – just send each value in a separate statement. For example:

Arduino

1

2

3

4

Thermal.write(27);

Thermal.write(61);

intzero=0;

Thermal.write(zero);

… will put the printer into offline mode. Notice how we used the variable “zero” for 0 – you can’t send a zero by itself. So we assign it to the variable and send that instead. Odd.

For out next example, let’s try out a few more commands:

Underlined text (the printer seemed to have issues with thick underlining, however your experience may vary)

Bold text

Double height and width

Here is the sketch:

Arduino

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

/*

Example 38.2 - Sparkfun Thermal Printer Test II (COM-10438)

http://tronixstuff.com/tutorials > chapter 38

Based on code by Nathan Seidle of Spark Fun Electronics 2011

*/

#include <SoftwareSerial.h>

SoftwareSerialThermal(2,3);

intzero=0;

intheatTime=80;

intheatInterval=255;

charprintDensity=15;

charprintBreakTime=15;

voidsetup()

{

Serial.begin(57600);// for debug info to serial monitor

Thermal.begin(19200);// to write to our new printer

initPrinter();

}

voidinitPrinter()

{

//Modify the print speed and heat

Thermal.write(27);

Thermal.write(55);

Thermal.write(7);//Default 64 dots = 8*('7'+1)

Thermal.write(heatTime);//Default 80 or 800us

Thermal.write(heatInterval);//Default 2 or 20us

//Modify the print density and timeout

Thermal.write(18);

Thermal.write(35);

intprintSetting=(printDensity<<4)|printBreakTime;

Thermal.write(printSetting);//Combination of printDensity and printBreakTime

Serial.println();

Serial.println("Printer ready");

}

voidloop()

{

// underline - one pixel

Thermal.write(27);

Thermal.write(45);

Thermal.write(1);

Thermal.println("Underline - thin");

Thermal.println("01234567890123456789012345678901");

Thermal.write(10);

// underline - two pixels

Thermal.write(27);

Thermal.write(45);

Thermal.write(2);

Thermal.println("Underline - thick");

Thermal.println("01234567890123456789012345678901");

Thermal.write(10);

// turn off underline

Thermal.write(27);

Thermal.write(45);

Thermal.write(zero);

delay(3000);

Thermal.write(10);

// bold text on

Thermal.write(27);

Thermal.write(32);

Thermal.write(1);

Thermal.println(" #### Bold text #### ");

Thermal.println("01234567890123456789012345678901");

delay(3000);

// bold text off

Thermal.write(27);

Thermal.write(32);

Thermal.write(zero);

Thermal.write(10);//Sends the LF to the printer, advances the paper

delay(3000);

// height/width enlarge

Thermal.write(29);

Thermal.write(33);

Thermal.write(255);

Thermal.println("ABCDEF");

Thermal.println("012345");

delay(3000);

// back to normal

Thermal.write(29);

Thermal.write(33);

Thermal.write(zero);

delay(3000);

Thermal.write(10);

Thermal.println("Back to normal...");

Thermal.write(10);

Thermal.write(10);

do{}while(1>0);// do nothing

}

And the results:

Frankly bold doesn’t look that bold, so I wouldn’t worry about it too much. However the oversized characters could be very useful, and still print relatively quickly.

Next on our list are barcodes. A normal UPC barcode has 12 digits, and our little printer can generate a variety of barcode types – see page twenty-two of the user manual. For our example we will generate UPC-A type codes and an alphanumeric version. Alphanumeric barcodes need capital letters, the dollar sign, percent sign, or full stop. The data is kept in an array of characters named … barCode[] and barCode[]2. Consider the functions printBarcode(),printBarcodeThick() and printBarcodeAlpha() in the following example sketch:

Thermal.write(printSetting);// Combination of printDensity and printBreakTime

Serial.println();

Serial.println("Printer ready");

}

voidprintBarcode(charzz[])

{

Thermal.write(29);//GS

Thermal.write(107);//k

Thermal.write(zero);//m = 0

for(intz=0;z<12;z++)

{

Thermal.write(zz[z]);

}

Thermal.write(zero);// bar code terminator

delay(3000);// necessary delay

Thermal.write(10);

Thermal.write(10);

Thermal.write(10);

}

voidprintBarcodeThick(charzz[])

{

Thermal.write(29);// specified height of barcode

Thermal.write(104);

Thermal.write(200);// 200 pixels high (default is 50)

Thermal.write(29);//GS

Thermal.write(107);//k

Thermal.write(zero);//m = 0

for(intz=0;z<12;z++)

{

Thermal.write(zz[z]);

}

Thermal.print(zero);// bar code terminator

delay(3000);// necessary delay

Thermal.write(29);// specified height of barcode

Thermal.write(104);

Thermal.write(50);// need to set back to 50 pixel height

delay(3000);

Thermal.write(10);

Thermal.write(10);

Thermal.write(10);

}

voidprintBarcodeAlpha(charzz[])

{

Thermal.write(29);//GS

Thermal.write(107);//k

Thermal.write(4);//m = 0

for(intz=0;z<16;z++)

{

Thermal.write(zz[z]);

}

// Thermal.print(zero); // bar code terminator

delay(3000);// necessary delay

Thermal.write(10);

Thermal.write(10);

Thermal.write(10);

}

voidloop()

{

printBarcode(barCode);

printBarcodeThick(barCode);

printBarcodeAlpha(barCode2);

do{}while(1>0);// do nothing

}

Notice in printBarcodeThick() we make use of the ability to change the vertical size of the barcode – the height in pixels is the third parameter in the group. And here is the result:

So there you have it – another practical piece of hardware previously considered to be out of our reach – is now under our control. Now you should have an understanding of the basics and can approach the other functions in the user guide with confidence. Please keep in mind that the price of this printer really should play a large part in determining suitability for a particular task. It does have issues printing large blocks of pixels, such as the double-width underlining and inverse text. This printer is great but certainly not for commercial nor high-volume use. That is what professional POS printers from Brother, Star, Epson, etc., are for. However for low-volume, personal or hobby use this printer is certainly a deal. As always, now it is up to you and your imagination to put this to use or get up to other shenanigans.

This article would not have been possible without the example sketches provided by Nathan Seidle, the founder and CEO of Sparkfun. If you meet him, shout him a beer. Please don’t knock off bus tickets or so on. I’m sure there are heavy penalties for doing so if caught.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.

In this article we will examine the first two products from a bundle sent for review by Snootlab, a Toulouse, France-based company that in their own words:

… designs and develops electronic products with an Open Hardware and Open Source approach. We are particularly specialized in the design of new shields for Arduino. The products we create are licensed under CC BY-SA v3.0 (as shown in documents associated with each of our creations). In accordance with the principles of the definition of Open Source Hardware (OSHW), we have signed it the 10th February 2011. We wish to contribute to the development of the ecosystem of “do it yourself” through original designs of products, uses and events.

Furthermore, all of their products are RoHS compliant and as part of the Open Hardware commitment, all the design files are available from the Snootlab website. First, let’s examine the Power Screwshield kit. This is a feature-laden prototyping shield suitable for Arduino Uno and compatible series boards. It can be used with the Mega, however not all of the I/O pins will be available.

Apart from obvious use as a prototyping shield, there are also three other useful features:

space for a 16-pin SOIC SMD part in the prototyping area;

a full line of screw terminals that connect to all the shield pin connections (in a similar way to the Wingshield Screwshield);

and a socket to allow power to be sourced from a standard computer ATX power supply, which brings 5V and 12V DC to the shield. I have never seen this implemented on a shield in the past – a very novel and useful idea.

If you are unfamiliar with the ATX power supply options, consider this image of the tronixstuff bench PC’s internals:

The connector we would use is the one with the four round pins in a single row. In recent times using PC power supplies as bench power supply units has become quite common, so the designers at Snootlab have taken advantage of this in a very clever way by allowing their Power ScrewShield to use these power supplies. Assembly of the shield is simple and well documented. Although it is self-explanatory, you can download an illustrated guide from here. The kit is packaged in a reusable ESD bag:

Assembly of the shield is simple and well documented. Although it is self-explanatory, you can download an illustrated guide from here. The kit is packaged in a reusable ESD bag:

… which contains all the necessary parts:

… and a very high quality PCB:

The PCB thickness is over 1mm, and as you can see from the image above the silk-screening describes all the areas of the PCB in a detailed manner. Note that this shield is much larger than a standard Arduino shield – this becomes obvious when compared with a standard prototyping shield:

Assembly was very smooth and quick. There are a couple of things to watch out for, for example you need to slide the terminal blocks together so that they are flush on the sides, such as:

… if you want to enable the 12V DC rail from the ATX power lead, short out the jumper SJ1 with a blob of solder:

… when soldering the PC power connector, be sure to make the clamp bracket flush with the socket, for example:

… and finally, to enable use of the shield’s LED, you need to cut the track in this area on the underside of the PCB:

Although at first the introduction of another Arduino prototyping shield may not have seemed that interesting – this version from Snootlab really goes all out to cover almost every possible need in a shield all at the same time. Sure, it is a lot larger – but none of the board space is wasted – and those terminal blocks would be very hand for making some more permanent-style prototypes with lots of external wiring. And the ability to accept power from a PC ATX-style power supply unit is certainly original and possibly very useful depending on your application. So if you need to create something that needs a lot of power, a lot of prototyping space, and a lot of wiring – this is the protoshield for you.

For the second half of the review we have the Snootlab I2C Power Protoshield. This is another example of an Arduino prototyping shield with some interesting twists. Apart from employing the same PC power connector as used with the Power ScrewShield, this shield is designed for hard-core I2C-bus enthusiasts. (What’s I2C? Check my tutorials). This is due to the 10-pin HE connector on the edge of the board – it contains pins for SCL, SDA, 3.3V, 5V and GND. With this you could use you own cable connections to daisy-chain other devices communicating via the I2C bus. Again, the shield is a kit and assembly was simple.

Like other Snootlab products, the kit arrives in a reusable ESD bag:

… with a high-quality thick PCB that has a very detailed silk-screen layer:

… and all the required parts are included:

When soldering in the shield connectors, using another shield as a jig can save time:

And we’re finished:

One could also mount a small solderless breadboad on the I2C Power Protoshield:

One great feature is the inclusion of an NCP1117DT33 3.3V 1A voltage regulator. Using this you can source 3.3 volts at up to one amp of current (only) when using the PC power supply connection. This is a great idea, as in the past it can be too easy to accidentally burn out the FTDI chip on an Arduino Duemilanove by drawing too much current from the 3.3V pin. The use of the external 3.3V supply is controlled by a jumper on the header pins here:

Finally, in the image above you can see the area for external I2C pull-up resistors. Generally with our Arduino the internal pull-up resistors in the microcontroller are adequate, however with many I2C devices in use (e.g. eight 24LC512 EEPROMS!) external pull-ups are required.

After examining the two shields I am impressed with the quality of the components and PCBs, as well as the interesting features described in the review. Theyare certainly unique and very much useful if required, especially the PC power supply connections. Support is available on the Snootlab website, and there is also a customer forum in French (use Google Translate). However the people at Snootlab converse in excellent English and have been easy to contact via email if you have any questions. Stay tuned for more interesting Snootlab product reviews.

As always, thank you for reading and I look forward to your comments and so on. Furthermore, don’t be shy in pointing out errors or places that could use improvement. Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts, follow on twitter, facebook, or join our Google Group.

[Disclaimer – the products reviewed in this article are promotional considerations made available by Snootlab]

A more contemporary type of lock could be controlled electronically, for example by a keypad where the user enters a series of digits to cause something to happen. Such as the keypad on this dodgy $30 safe from Officeworks:

As you can see there is a button for each digit. You would think that this would be a good idea – however people can watch you enter the digits, or users can be silly enough to write down the combination somewhere. In some cases the more cunning monkeys have even placed cameras that can observe keypads to record people entering the combination. There must be a better way. Possibly! However in the meanwhile you can consider my idea instead – just have one button. Only one button – and the combination is made up of the time that elapses between presses of the button. There are many uses for such an odd lock:

A type of combination lock that controls an electric door strike, or activates a device of some sort;

A way of testing mind-hand coordination for skill, or the base of a painfully frustrating game;

Perhaps an interlock on motor vehicle to prevent drink driving. After a few drinks there’s no way you could get the timing right. Then again, after a double espresso or two you might have problems as well.

How does it work? Consider the following:

We measure the duration of time between each press of the button (in this case – delay 1~4). These delay times are then compared against values stored in the program that controls the lock. It is also prudent to allow for some tolerance in the user’s press delay – say plus or minus ten to fifteen percent. We are not concerned with the duration of each button press, however it is certainly feasible.

To create this piece of hardware is quite easy, and once again we will use the Arduino way of doing things. For prototyping and experimenting it is simple enough to create with a typical board such as a Uno or Eleven and a solderless breadboard – however to create a final product you could minimise it by using a bare-bones solution (as described here). Now let’s get started…

For demonstration purposes we have a normally-open button connected to digital pin 2 on our Arduino-compatible board using the 10k ohm pull down resistor as such:

The next thing to do is determine our delay time values. Our example will use five presses, so we measure four delays. With the following sketch, you can generate the delay data by pushing the button yourself – the sketch will return the delay times on the serial monitor:

Arduino

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

/*

Single-button combination lock

Delay Time data generation sketch - John Boxall June 2011

http://tronixstuff.com/projects | CC by-sa-nc

*/

intcount=0;

unsignedlonga[]={0,0,0,0,0,0};

unsignedlongdel[]={0,0,0,0,0};

voidsetup()

{

pinMode(2,INPUT);

Serial.begin(115200);

Serial.println("Ready...");

}

voiddataCapture()

{

a[count]=millis();

delay(500);// for button debounce, your value may differ

count++;

}

voiddisplayData()

{

// calcualate delays between keypresses

del[0]=a[1]-a[0];

del[1]=a[2]-a[1];

del[2]=a[3]-a[2];

del[3]=a[4]-a[3];

// display delay data for use in combination lock sketch

for(inta=0;a<4;a++)

{

Serial.println();

Serial.print("Delay ");

Serial.print(a);

Serial.print(" use ");

Serial.print(del[a]);

Serial.println(" ms");

}

Serial.println("- - - - - - - - -");

count=0;

}

voidloop()

{

if(digitalRead(2)==HIGH)

{

dataCapture();

}

if(count>4)

{

displayData();

}

}

So what’s going on the this sketch? Each time the button is pressed a reading of millis() is taken and stored in an array. [More on millis() in the tutorial]. Once the button has been pressed five times, the difference in time between each press is calculated and stored in the array del[]. Note the use of a 500 ms delay in the function dataCapture(), this is to prevent the button bouncing and will need to be altered to suit your particular button. Finally the delay data is then displayed on the serial monitor. For example:

The example was an attempt to count one second between each press. This example also illustrates the need to incorporate some tolerance in the actual lock sketch. With a tolerance of +/- 10% and delay values of one second, the lock would activate. With 5% – no. Etcetera.

Now for the lock sketch. Again it measures the millis() value on each button press and after five presses calculates the duration between each press. Finally in the function checkCombination() the durations are compared against the stored delay values (generated using the first sketch) which are stored in the array del[]. In our example lock sketch we have values of one second between each button press. The tolerance is stored as a decimal fraction in the variable tolerance; for example to have a tolerance of ten percent, use 0.1:

Arduino

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

/*

Single-button combination lock - John Boxall June 2011

http://tronixstuff.wordpress.com/projects | CC by-sa-nc

combilock2.pde

*/

intcount=0;

unsignedlonga[]={0,0,0,0,0};

unsignedlongb[]={0,0,0,0,0};

unsignedlongdel[]={1000,2000,3000,4000};// these are the values obtained from running combilock1.pde

When choosing your time delays, ensure they are larger than the value used for button debounce (the delay() function call) in the dataCapture() function. Notice the two functions success() and failure() – these will contain the results of what happens when the user successfully enters the combination or does not. For a demonstration of the final product, I have connected an LCD to display the outcomes of the entry attempts. You can download the sketch from here. The key used in this example is 1,2,3,4 seconds:

Although there are four buttons on the board used in the video, only one is used. Well I hope someone out there found this interesting or slightly useful…

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.

In this article we introduce the millis(); function and put it to use to create various timing examples.

Millis? Nothing to do with lip-syncers… hopefully you recognised milli as being the numerical prefix for one-thousandths; that is multiplying a unit of measure by 0.001 (or ten to the power of negative 3). Interestingly our Arduino systems will count the number of milliseconds (thousands of a second) from the start of a sketch running until the count reaches the maximum number capable of being stored in the variable type unsigned long (a 32-bit [four byte] integer – that ranges from zero to (2^32)-1.

(2^32)-1, or 4294967295 milliseconds converts to 49.71027-odd days. The counter resets when the Arduino is reset, it reaches the maximum value or a new sketch is uploaded. To get the value of the counter at a particular juncture, just call the function – for example:

Arduino

1

start=millis();

Where start is an unsigned long variable. Here is a very simple example to show you millis() in action:

Arduino

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

/*

Example 37.1 - millis() demonstration

http://tronixstuff.com/tutorials > chapter 37

John Boxall | CC by-sa-nc

*/

unsignedlongstart,finished,elapsed;

voidsetup()

{

Serial.begin(9600);

}

voidloop()

{

Serial.println("Start...");

start=millis();

delay(1000);

finished=millis();

Serial.println("Finished");

elapsed=finished-start;

Serial.print(elapsed);

Serial.println(" milliseconds elapsed");

Serial.println();

delay(500);

}

The sketch stores the current millis count in start, then waits one second, then stores the value of millis again in finished. Finally it calculates the elapsed time of the delay. In the following screen dump of the serial monitor, you can see that the duration was not always exactly 1000 milliseconds:

To put it simply, the millis function makes use of an internal counter within the ATmega microcontroller at the heart of your Arduino. This counter increments every clock cycle – which happens (in standard Arduino and compatibles) at a clock speed of 16 Mhz. This speed is controlled by the crystal on the Arduino board (the silver thing with T16.000 stamped on it):

Crystal accuracy can vary depending on external temperature, and the tolerance of the crystal itself. This in turn will affect the accuracy of your millis result. Anecdotal experience has reported the drift in timing accuracy can be around three or four seconds per twenty-four hour period. If you are using a board or your own version that is using a ceramic resonator instead of a crystal, note that they are not as accurate and will introduce the possibility of higher drift levels. If you need a much higher level of timing accuracy, consider specific timer ICs such as the Maxim DS3232.

Now we can make use of the millis for various timing functions. As demonstrated in the previous example sketch, we can calculate elapsed time. To take this idea forward, let’s make a simple stopwatch. Doing so can be as simple or as complex as necessary, but for this case we will veer towards simple. On the hardware perspective, we will have two buttons – Start and Stop – with the 10k ohm pull-down resistors connected to digital pins 2 and 3 respectively.

When the user presses start the sketch will note the value for millis – then after stop is pressed, the sketch will again note the value for millis, calculate and display the elapsed time. The user can then press start to repeat the process, or stop for updated data. Here is the sketch:

Arduino

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

/*

Example 37.2 – Super-basic stopwatch using millis();

http://tronixstuff.com/tutorials > chapter 37

John Boxall | CC by-sa-nc

*/

unsignedlongstart,finished,elapsed;

voidsetup()

{

Serial.begin(9600);

pinMode(2,INPUT);// start button

pinMode(3,INPUT);// stop button

Serial.println("Press 1 for Start/reset, 2 for elapsed time");

}

voiddisplayResult()

{

floath,m,s,ms;

unsignedlongover;

elapsed=finished-start;

h=int(elapsed/3600000);

over=elapsed%3600000;

m=int(over/60000);

over=over%60000;

s=int(over/1000);

ms=over%1000;

Serial.print("Raw elapsed time: ");

Serial.println(elapsed);

Serial.print("Elapsed time: ");

Serial.print(h,0);

Serial.print("h ");

Serial.print(m,0);

Serial.print("m ");

Serial.print(s,0);

Serial.print("s ");

Serial.print(ms,0);

Serial.println("ms");

Serial.println();

}

voidloop()

{

if(digitalRead(2)==HIGH)

{

start=millis();

delay(200);// for debounce

Serial.println("Started...");

}

if(digitalRead(3)==HIGH)

{

finished=millis();

delay(200);// for debounce

displayResult();

}

}

The calls to delay() are used to debounce the switches – these are optional and their use will depend on your hardware. Below is an example of the sketch’s serial monitor output – the stopwatch has started, and then button two pressed six times across periods of time:

If you had a sensor at the start and end of a fixed distance, speed could be calculated: speed = distance ÷ time.

You can also make a speedometer for a wheeled form of motion, for example a bicycle. At the present time I do not have a bicycle to mess about with, however we can describe the process to do so – it is quite simple. (Disclaimer – do so at your own risk etc.) First of all, let’s review the necessary maths. You will need to know the circumference of the wheel. Hardware – you will need a sensor. For example – a reed switch and magnet. Consider the reed switch to be a normally-open button, and connect as usual with a 10k ohm pull-down resistor. Others may use a hall-effect sensor – each to their own). Remember from maths class:

where r is the radius of the circle. Now that you have the wheel circumference, this value can be considered as our ‘fixed distance’, and therefore the speed can be calculated by measuring the elapsed time between of a full rotation.

Your sensor – once fitted – should act in the same method as a normally-open button that is pushed every rotation. Our sketch will measure the time elapsed between every pulse from the sensor. To do this, our example will have the sensor output connected to digital pin 2 – as it will trigger an interrupt to calculate the speed. (Interrupts? See chapter three). The sketch will otherwise be displaying the speed on a normal I2C-interface LCD module. The I2C interface is suggested as this requires only 4 wires from the Arduino board to the LCD – the less wires the better.

There isn’t that much going on – every time the wheel completes one revolution the signal from the sensor will go from low to high – triggering an interrupt which calls the function speedCalc(). This takes a reading of millis() and then calculates the difference between the current reading and the previous reading – this value becomes the time to cover the distance (which is the circumference of the wheel relative to the sensor – stored in

Arduino

1

floatcircMetric=1.2;

and is measured in metres). It finally calculates the speed in km/h and MPH. Between interrupts the sketch displays the updated speed data on the LCD as well as the raw time value for each revolution for curiosity’s sake. In real life I don’t think anyone would mount an LCD on a bicycle, perhaps an LED display would be more relevant.

In the meanwhile, you can see how this example works in the following short video clip. Instead of a bike wheel and reed switch/magnet combination, I have connected the square-wave output from a function generator to the interrupt pin to simulate the pulses from the sensor, so you can get an idea of how it works:

That just about sums up the use of millis() for the time being. There is also the micros(); function which counts microseconds. So there you have it – another practical function that can allow more problems to be solved via the world of Arduino. As always, now it is up to you and your imagination to find something to control or get up to other shenanigans.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.

This is the second of several chapters in which we are investigating the SPI data bus, and how we can control devices using it with our Arduino systems. If you have not done so already, please read part one of the SPI articles. Again we will learn the necessary theory, and then apply it by controlling a variety of devices. As always things will be kept as simple as possible.

First on our list today is the use of multiple SPI devices on the single bus. We briefly touched on this in part one, by showing how multiple devices are wired, for example:

Notice how the slave devices share the clock, MOSI and MISO lines – however they both have their own chip select line back to the master device. At this point a limitation of the SPI bus becomes prevalent – for each slave device we need another digital pin to control chip select for that device. If you were looking to control many devices, it would be better to consider finding I2C solutions to the problem. To implement multiple devices is very easy. Consider the example 34.1 from part one – we controlled a digital rheostat. Now we will repeat the example, but instead control four instead of one. For reference, here is the pinout diagram:

Doing so may sound complex, but it is not. We connect the SCK, MOSI and MISO pins together, then to Arduino pins D13, D11, D12 respectively. Each CS pin is wired to a separate Arduino digital pin. In our example rheostats 1 to 4 connect to D10 through to D7 respectively. To show the resistance is changing on each rheostat, there is an LED between pin 5 and GND and a 470 ohm resistor between 5V and pin 6. Next, here is the sketch:

// our MCP4162s requires data to be sent MSB (most significant byte) first

}

voidsetValue(intl,intvalue)

// sends value 'value' to SPI device on CS digital out pin 'l'

{

digitalWrite(l,LOW);

SPI.transfer(0);// send command byte

SPI.transfer(value);// send value (0~255)

digitalWrite(l,HIGH);

}

voidallOff()

// sets all pots to max resistance

{

setValue(led1,255);

setValue(led2,255);

setValue(led3,255);

setValue(led4,255);

}

voidpulse(intl)

{

allOff();

for(inta=255;a>=0;--a)

{

setValue(l,a);

delay(del);

}

for(inta=0;a<256;a++)

{

setValue(l,a);

delay(del);

}

}

voidpulseAll()

{

allOff();

for(inta=255;a>=0;--a)

{

setValue(led1,a);

setValue(led2,a);

setValue(led3,a);

setValue(led4,a);

delay(del);

}

for(inta=0;a<256;a++)

{

setValue(led1,a);

setValue(led2,a);

setValue(led3,a);

setValue(led4,a);

delay(del);

}

}

voidloop()

{

pulse(led1);

pulse(led2);

pulse(led3);

pulse(led4);

pulseAll();

}

Although the example sketch may be longer than necessary, it is quite simple. We have four SPI devices each controlling one LED, so to keep things easy to track we have defined led1~led4 to match the chip select digital out pins used for each SPI device. Then see the first four lines in void setup(); these pins are set to output in order to function as required. Next – this is very important – we set the pins’ state to HIGH. You must do this to every chip select line! Otherwise more than one CS pins may be initially low in some instances and cause the first data sent from MOSI to travel along to two or more SPI devices. With LEDs this may not be an issue, but for motor controllers … well it could be.

The other point of interest is the function

Arduino

1

voidsetValue(intl,intvalue)

We pass the value for the SPI device we want to control, and the value to send to the device. The value for l is the chip select value for the SPI device to control, and ranges from 10~7 – or as defined earlier, led1~4. The rest of the sketch is involved in controlling the LED’s brightness by varying the resistance of the rheostats. Now to see example 36.1 in action via the following video clip:

Next on the agenda is a digital-to-analogue converter, to be referred to using the acronym DAC. What is a DAC? In simple terms, it accepts a numerical value between zero and a maximum value (digital) and outputs a voltage between the range of zero and a maximum relative to the input value (analogue). One could consider this to be the opposite of the what we use the function analogRead(); for. For our example we will use a Microchip MCP4921 (data sheet.pdf):

(Please note that this is a beginners’ tutorial and is somewhat simplified). This DAC has a 12-bit resolution. This means that it can accept a decimal number between 0 and 4095 – in binary this is 0 to 1111 1111 1111 (see why it is called 12-bit) – and the outpout voltage is divided into 4096 steps. The output voltage for this particular DAC can fall between 0 and just under the supply voltage (5V). So for each increase of 1 in the decimal input value, the DAC will output around 1.221 millivolts.

It is also possible to reduce the size of the voltage output steps by using a lower reference voltage. Then the DAC will consider the reference voltage to be the maximum output with a value of 4095. So (for example) if the reference voltage was 2.5V, each increase of 1 in the decimal input value, the DAC will output around 0.6105 millivolts. The minimum reference voltage possible is 0.8V, which offers a step of 200 microvolts (uV).

The output of a DAC can be used for many things, such as a function generator or the playback of audio recorded in a digital form. For now we will examine how to use the hardware, and monitoring output on an oscilloscope. First we need the pinouts:

By now these sorts of diagrams shouldn’t present any problems. In this example, we keep pin 5 permanently set to GND; pin 6 is where you feed in the reference voltage – we will set this to +5V; AVss is GND; and Vouta is the output signal pin – where the magic comes from 🙂 The next thing to investigate is the MCP4921’s write command register:

Bits 0 to 11 are the 12 bits of the output value; bit 15 is an output selector (unused on the MPC4921); bit 14 controls the input buffer; bit 13 controls an inbuilt output amplifier; and bit 12 can shutdown the DAC. Unlike previous devices, the input data is spread across two bytes (or a word of data). Therefore a small amount of work needs to be done to format the data ready for the DAC. Let’s explain this through looking at the sketch for example 36.2 that follows. The purpose of the sketch is to go through all possible DAC values, from 0 to 4095, then back to 0 and so on.

First. note the variable outputvalue – it is a word, a 16-bit unsigned variable. This is perfect as we will be sending a word of data to the DAC. We put the increasing/decreasing value for a into outputValue. However as we can only send bytes of data at a time down the SPI bus, we will use the function highbyte() to separate the high side of the word (bits 15~8) into a byte variable called data.

We then use the bitwise AND and OR operators to set the parameter bits 15~12. Then this byte is sent to the SPI bus. Finally, the function lowbyte() is used to send the low side of the word (bits 7~0) into data and thence down the SPI bus as well.

By now we have covered in detail how to send data to a device on the SPI bus. But how do we receive data from a device?

Doing so is quite simple, but some information is required about the particular device. For the rest of this chapter, we will use the Maxim DS3234 “extremely accurate” real-time clock. Please download the data sheet (.pdf) now, as it will be referred to many times.

The DS3234 is not available in through-hole packaging, so we will be using one that comes pre-soldered onto a very convenient breakout board:

It only takes a few moments to solder in some header pins for breadboard use. The battery type is CR1220 (12 x 2.0mm, 3V); if you don’t have a battery you will need to short out the battery holder with some wire otherwise the IC will not work. Readers have reported that the IC doesn’t keep time if the USB and external power are both applied to the Arduino at the same time.

A device will have one or more registers where information is read from and written to. Look at page twelve of the DS3234 data sheet, there are twenty-three registers, each containing eight bits (one byte) of data. Please take note that each register has a read and write address. An example – to retrieve the contents of the register at location 08h (alarm minutes) and place it into the byte data we need to do the following:

Arduino

1

2

3

4

digitalWrite(10,LOW);// select the DS3234 that has its CS line on digital 10

SPI.transfer(0x08);// tell the DS3234 device we're requesting data from the register at 08h

data=SPI.transfer(0);// the DS3234 sends the data back and stores it in the byte data

digitalWrite(10,HIGH);// deselect the DS3234 if finished with it

Don’t forget to take note of the function SPI.setBitOrder(MSBFIRST); in your sketch, as this also determines the bit order of the data coming from the device. To write data to a specific address is also quite simple, for example:

Arduino

1

2

3

4

digitalWrite(10,LOW);

SPI.transfer(0x80);// tells the device which address to write to

SPI.transfer(b00001010);// you can send any representation of a byte

digitalWrite(10,HIGH);

Up to this point, we have not concerned ourselves with what is called the SPI data mode. The mode determines how the SPI device interprets the ‘pulses’ of data going in and out of the device. For a well-defined explanation, please read this article. With some devices (and in our forthcoming example) the data mode needs to be defined. So we use:

Arduino

1

SPI.setDataMode(SPI_MODE1);

to set the data mode, within void(setup);. To determine a device’s data mode, as always – consult the data sheet. With our DS3234 example, the mode is mentioned on page 1 under Features List.

Finally, let’s delve a little deeper into SPI via the DS3234. The interesting people at Sparkfun have already written a good demonstration sketch for the DS3234, so let’s have a look at that and deconstruct it a little to see what is going on. You can download the sketch below from here, then change the file extension from .c to .pde.

Don’t let the use of custom functions and loops put you off, they are there to save time. Looking in the function SetTimeDate();, you can see that the data is written to the registers 80h through to 86h (skipping 83h – day of week) in the way as described earlier (set CS low, send out address to write to, send out data, set CS high). You will also notice some bitwise arithmetic going on as well. This is done to convert data between binary-coded decimal and decimal numbers.

Why? Go back to page twelve of the DS3234 data sheet and look at (e.g.) register 00h/80h – seconds. The bits 7~4 are used to represent the ‘tens’ column of the value, and bits 3~0 represent the ‘ones’ column of the value. So some bit shifting is necessary to isolate the digit for each column in order to convert the data to decimal. For other ways to convert between BCD and decimal, see the examples using the Maxim DS1307 in chapter seven.

Finally here is another example of reading the time data from the DS3234:

So there you have it – more about the world of the SPI bus and how to control the devices within.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.

Create video output from your Arduino in chapter 35 of tutorials about the Arduino universe. The first chapter is here, the complete series is detailed here.

[Updated 10/01/2013]

In this chapter we will examine something different – the ability of our Arduino and compatible boards to create composite video output. In other words, displaying stuff from the Arduino on a TV. A lot of people were unaware of the ability to do this, however the process is very simple and not difficult to implement from a hardware perspective. Within this chapter we will learn to construct the minimum hardware required and demonstrate basic functions to get started.

To whet your appetite, here is a quick video demonstration of what is possible:

You can’t expect too much from a 16 MHz microcontroller without a video card… but the price is right, and with some imagination and the right functions you can do quite well. To make this happen we need to knock out some hardware of our own. Connection is very easy. First we need to locate three pins on our Arduino board. They will be used to output Sync, Video and also GND. For those with Arduino Uno/Freetronics Eleven etc Sync is digital 9, video is digital 7 and GND is … GND. If you have a Mega/Mega2560 Sync is digital 11 and video is A7. There is also the ability to generate audio with the methods in this article, and if you want to do this the Uno (etc.) pin is digital 11 or 10 on the Mega.

The monitor or television used needs to have a composite video-in socket (jack). For those with older televisions that have a VCR connected, you could use the video-in socket on the VCR. The schematic for video out is very simple, you only need two normal 0.25W resistors and a video lead:

If you’re not up for soldering into an RCA plug, a simple way is to chop up a standard video lead as such:

Then just wire the termination of the two resistors to the centre core (“pin”) and GND to the shield. For the purpose of this article I have made a quick TV-out shield that also includes a thumb joystick (as reviewed here).

A real triumph of engineering… however it solves the problem. The vertical trimmer is connected to A0; the horizontal to A1; the button to digital 8 via a 10k0 pull-up resistor. Next, you will need to download and install the arduino-tvout library. It can be found here. We will use the TVoutBeta1.zip version. Those of you who may have a nootropic design Hackvision – please note your library is different.

Now to see how to integrate TV-out into our sketch. We will run through the basic functions which integrated with your imagination should see some interesting results… So let’s go!

For every project, place these two lines at the top of your sketch:

Arduino

1

2

#include "TVout.h"

TVoutTV;

The first brings in the library, and the second line creates an instance of TV to use with the library functions. Next, we need to activate TVout and select the appropriate broadcast standard (PAL or NTSC). In void setup() use either

Arduino

1

2

TV.start_render(_NTSC)// for NTSC (or)

TV.start_render(_PAL);// for PAL system

Now for the main functions. The first one of interest will be:

Arduino

1

TV.clear_screen();

which … clears the screen. Or if you would like to fill the screen with white, use

Arduino

1

TV.fill_screen(1);

Moving on – to write some text. First we need to select a font. There are three basic fonts to choose from:

font4x6 (each character being 4 pixels by 6 pixels, etc.)

font6x8

font8x8

Well there is four, but it wouldn’t display for me. Working on it! To choose a font use:

Arduino

1

TV.select_font(font4x6);// using font4x6

Then to write the text, choose the screen location with:

Arduino

1

TV.set_cursor(x,y);

then display the text with:

Arduino

1

TV.print("Hello, world...");// etc

You can also use TV.println(); to add a carriage return as expected. Display single characters with a position in the one function using:

Arduino

1

TV.print_char(x,y,c);// c is the character to display

So let’s have a look at the various fonts in action with the following sketch:

Now to move into the 1970s with some basic graphical functions. We have a screen resolution of 128 by 96 pixels to work with. When planning your display, you need to ensure that the sketch never attempts to display a pixel outside of the 128 x 96 screen area. Doing so generally causes the Arduino to reboot.

First let’s start with basic pixels. To draw a pixel, use:

Arduino

1

TV.set_pixel(x,y,z);

where x and y are the coordinates of the pixel, and z is the colour (1 = white, 0 = black, 2 = inverse of current pixel’s colour). You want more than a pixel? How about a line:

Have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.

Time once again to examine another kit. This week we have the nootropic design Digit Shield for Arduino Uno/Duemilanove and compatible boards. Although a finger can be called a digit this shield is not some sort of biotechnological experiment – instead it gives us four seven-segment LED displays to show various forms of numerical data from our Arduino sketches.

Although many people may be tempted to use a standard LCD unit, there are a few advantages to using an LED display – such as digit size, enhanced readability in daylight, and LED displays are generally much more robust than LCDs. Therefore there should be many uses for the Digit Shield. Furthermore, the people at nootropic design have been awesome as they support the Open Hardware Definition 1.0, and the Digit Shield design files have been made available under Creative Commons attribution-share alike.

First let’s run through construction, then operation with some demonstrations. The kit arrives in a nice reusable bag with a pointer to the online instructions:

Kit construction was relatively simple thanks to the excellent instructions by nootropic design. All the parts required for completion are included, except for IC sockets:

My demonstration kit included green LED displays, however it is also available in red-orange, depending on the retail outlet you choose. Once again the PCB is well laid out, with a good solder mask and a nicely labelled silk screen on top:

Now to start soldering. The process is nothing out of the ordinary, and should take around half an hour at the most. First in are the resistors:

Notice how the current-limiting resistors for the LED segments will be under the LED displays. So now we solder in the LED modules and create a resistor jail:

Now for the shift register and BCD to decimal ICs. I found inserting them a little tricky due to my large hands and the LED display already being in place, so it would be easier to fit the ICs before the LED modules:

This leaves us with the transistors, capacitors, header sockets and the reset button:

After soldering the reset button, you may need trim down the solder and legs (as shown below) otherwise there is a possibility they will rub the DC input socket on the Arduino board:

Finally the shield pins are fitted and the shield is ready:

The next task is to download and install the Digit Shield’s Arduino library. The latest version can be found here. Extract the folder into your

Arduino

1

../arduino-1x/libraries

folder, then restart the Arduino IDE software. A quick test of the shield can be accomplished with the SimpleCounter sketch available from the inbuilt examples. To find this, select File>Examples>DigitShield>SimpleCounter in the Arduino IDE, and upload the sketch. Hold onto the desk as you watch some numbers increment:

Using the shield in your own sketch is quite simple. Instead of reinventing the wheel there is an excellent explanation of the various functions available on the lower section of this page. A very useful feature is when the shield cannot display a number – it shows all four decimal points instead. The only slight criticism that comes to mind is the inability to directly display hexadecimal digits A~F, as the LED units lend themselves nicely to doing so; or the option of controlling each LED segment individually with a simple function. So let’s see if that is possible…

One of the joys of open hardware is the fact we can get the schematic, see how it works and attempt to solve such dilemmas ourselves. For those without software that can read Cadsoft EAGLE files, here is the schematic in .pdf format. The section we need to see is how the LED segments are driven. Look for the 74HC595 and 74LS247 ICs. Serial data is shifted out from the Arduino digital pins to the 74HC595 shift register. (For more information about how 74HC595s work with Arduino please visit this tutorial).

Outputs A~D (Q0~Q3) represent binary-coded decimal output and the outputs E~H (Q4~Q7) control the transistors which select the current digit to use. The BCD output is fed to the 74LS247 BCD to seven-segment drive IC. Although this is a very useful IC, it can only display the decimal digits and a few odd characters (see page two of the data sheet.pdf). So this leaves us unable to modify our sketches or the shield library to solve our problem. Such is life!

Perhaps the people at nootropic design can consider a change in the hardware for the next version to incorporate such requirements. However there are several projects available in the Digit Shield’s website that may be of interest, including a way to daisy-chain more than one shield at a time.

Nevertheless the Digit Shield is a simple kit that makes displaying Arduino-generated numerical data simple and clear. Furthermore lovers of blinking LEDs will have a ball. For further questions about the Digit Shield contact nootropic design or perhaps post on their forum.

As always, thank you for reading and I look forward to your comments and so on. Furthermore, don’t be shy in pointing out errors or places that could use improvement. Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts, follow me on twitter or facebook, or join our Google Group for further discussion.

Time for another kit review – the nootropics design Hackvision, a nice change from test equipment. The purpose of the Hackvision is to allow the user to create retro-style arcade games and so on that can be played on a monitor or television set with analogue video input. Although the display resolution is only 128 by 96 pixels, this is enough to get some interesting action happening. Frankly I didn’t think the Arduino hardware environment alone was capable of this, so the Hackvision was a pleasant surprise.

Assembly is quick and relatively simple, the instructions are online and easy to follow. All the parts required are included:

The microcontroller is pre-loaded with two games so you can start playing once construction has finished. However you will need a 5V FTDI cable if you wish to upload new games as the board does not have a USB interface. The board is laid out very clearly, and with the excellent silk-screen and your eyes open construction will be painless. Note that you don’t need to install R4 unless necessary, and if your TV system is PAL add the link which is between the RCA sockets. Speaking of which, when soldering them in, bend down the legs to lock them in before soldering, as such:

Doing so will keep them nicely flush with the PCB whilst soldering. Once finished you should have something like this:

All there is to do now is click the button covers into place, plug in your video and audio RCA leads to a monitor, insert nine volts of DC power, and go:

Nice one. For the minimalist users out there, be careful if playing games as the solder on the rear of the PCB can be quite sharp. Included with the kit is some adhesive rubber matting to attach to the underside to smooth everything off nicely. However only fit this once you have totally finished with soldering and modifying the board, otherwise it could prove difficult to remove neatly later on. Time to play some games… in the following video you can see how poor my reflexes are when playing Pong and Space Invaders:

Well that takes me back. There are some more contemporary games and demonstration code available on the Hackvision games web page. For the more involved Hackvision gamer, there are points on the PCB to attach your own hand-held controls such as paddles, nunchuks and so on. There is a simple tutorial on how to make your own paddles here.

Those who have been paying attention will have noticed that although the Hackvision PCB is not the standard Arduino Duemilanove-compatible layout, all the electronics are there. Apart from I/O pins used by the game buttons, you have a normal Arduino-style board with video and audio out. This opens up a whole world of possibilities with regards to the display of data in your own Arduino sketches (software). From a power supply perspective, note that the regulator is a 78L05 which is only good for 100mA of current, and the board itself uses around 25mA.

To control the video output, you will need to download and install the hackvision-version arduino-tvout library. Note that this library is slightly different to the generic arduino-tvout library with regards to function definitions and parameters. To make use of the included buttons easier, there is also the controllers library. Here is a simple, relatively self-explanatory sketch that demonstrates some uses of the tvout functions:

Arduino

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

/*

nootropics Hackvision display demo two

http://tronixstuff.com > kit reviews

John Boxall 13 May 2011 | CC by-sa

*/

#include "avr/pgmspace.h"

#include "TVout.h"

#include "video_gen.h"

#include "EEPROM.h"

#include "Controllers.h"

intx,y=0;

intd=500;// used for various delays

// declare screen resolution

#define W 136

#define H 98

// create instance of TV

TVouttv;

voidsetup(){

// If pin 12 is pulled LOW, then the PAL jumper is shorted.

pinMode(12,INPUT);

digitalWrite(12,HIGH);

if(digitalRead(12)==LOW){

tv.begin(_PAL,W,H);

// Since PAL processing is faster, we need to slow the game play down.

}

else{

tv.begin(_NTSC,W,H);

}

randomSeed(analogRead(0));

}

voidrandomPixels()

{

tv.clear_screen();// clears the screen

for(inta=0;a<500;a++)

{

x=random(128);

y=random(96);

tv.set_pixel(x,y,1);// 1 for white, 0 for black, 2 for inverse of current colour at that location

I will be the first to admit that my imagination is lacking some days. However with the sketch above hopefully you can get a grip on how the functions work. But there are some very good game implementations out there, as listed on the Hackvision games page. After spending some time with this kit, I feel that there is a lack of documentation that is easy to get into. Sure, having some great games published is good but some beginners’ tutorials would be nice as well. However if you have the time and the inclination, there is much that could be done. In the meanwhile you can do your own sleuthing with regards to the functions by examining the TVout.cpp file in the Hackvision tvout library folder.

For further questions about the Hackvision contact nootropic design or perhaps post on their forum. However the Hackvision has a lot of potential and is an interesting extension of the Arduino-based hardware universe – another way to send data to video monitors and televisions, and play some fun games.If you are looking for a shield-based video output device, perhaps consider the Batsocks Tellymate.

As always, thank you for reading and I look forward to your comments and so on. Furthermore, don’t be shy in pointing out errors or places that could use improvement. Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts, follow me on twitter or facebook, or join our Google Group for further discussion.

This is the first of two chapters in which we are going to start investigating the SPI data bus, and how we can control devices using it with our Arduino systems. The SPI bus may seem to be a complex interface to master, however with some brief study of this explanation and practical examples you will soon become a bus master! To do this we will learn the necessary theory, and then apply it by controlling a variety of devices. In this tutorial things will be kept as simple as possible.

But first of all, what is it? And some theory…

SPI is an acronym for “Serial Peripheral Interface”. It is a synchronous serial data bus – data can travel in both directions at the same time, as opposed to (for example) the I2C bus that cannot do so. To allow synchronous data transmission, the SPI bus uses four wires. They are called:

MOSI – Master-out, Slave-in. This line carries data from our Arduino to the SPI-controlled device(s);

MISO – Master-in, Slave out. This line carries data from the SPI-controlled device(s) back to the Arduino;

SS – Slave-select. This line tells the device on the bus we wish to communicate with it. Each SPI device needs a unique SS line back to the Arduino;

SCK – Serial clock.

Within these tutorials we consider the Arduino board to be the master and the SPI devices to be slaves. On our Arduino Duemilanove/Uno and compatible boards the pins used are:

SS – digital 10. You can use other digital pins, but 10 is generally the default as it is next to the other SPI pins;

MOSI – digital 11;

MISO – digital 12;

SCK – digital 13;

Arduino Mega users – MISO is 50, MOSI is 51, SCK is 52 and SS is usually 53. If you are using an Arduino Leonardo, the SPI pins are on the ICSP header pins. See here for more information. You can control one or more devices with the SPI bus. For example, for one device the wiring would be:

Data travels back and forth along the MOSI and MISO lines between our Arduino and the SPI device. This can only happen when the SS line is set to LOW. In other words, to communicate with a particular SPI device on the bus, we set the SS line to that device to LOW, then communicate with it, then set the line back to HIGH. If we have two or more SPI devices on the bus, the wiring would resemble the following:

Notice how there are two SS lines – we need one for each SPI device on the bus. You can use any free digital output pin on your Arduino as an SS line. Just remember to have all SS lines high except for the line connected to the SPI device you wish to use at the time.

Data is sent to the SPI device in byte form. You should know by now that eight bits make one byte, therefore representing a binary number with a value of between zero and 255. When communicating with our SPI devices, we need to know which way the device deals with the data – MSB or LSB first. MSB (most significant bit) is the left-hand side of the binary number, and LSB (least significant bit) is the right-hand side of the number. That is:

Apart from sending numerical values along the SPI bus, binary numbers can also represent commands. You can represent eight on/off settings using one byte of data, so a device’s parameters can be set by sending a byte of data. These parameters will vary with each device and should be illustrated in the particular device’s data sheet. For example, a digital potentiometer IC with six pots:

This device requires two bytes of data. The ADDR byte tells the device which of six potentiometers to control (numbered 0 to 5), and the DATA byte is the value for the potentiometer (0~255). We can use integers to represent these two values. For example, to set potentiometer number two to 125, we would send 2 then 125 to the device.

How do we send data to SPI devices in our sketches?

First of all, we need to use the SPI library. It is included with the default Arduino IDE installation, so put the following at the start of your sketch:

Arduino

1

#include "SPI.h"

Next, in void.setup() declare which pin(s) will be used for SS and set them as OUTPUT. For example,

Arduino

1

pinMode(ss,OUTPUT);

where ss has previously been declared as an integer of value ten. Now, to activate the SPI bus:

Arduino

1

SPI.begin();

and finally we need to tell the sketch which way to send data, MSB or LSB first by using

Arduino

1

SPI.setBitOrder(MSBFIRST);

or

Arduino

1

SPI.setBitOrder(LSBFIRST);

When it is time to send data down the SPI bus to our device, three things need to happen. First, set the digital pin with SS to low:

Arduino

1

digitalWrite(SS,LOW);

Then send the data in bytes, one byte at a time using:

Arduino

1

SPI.transfer(value);

Value can be an integer/byte between zero and 255. Finally, when finished sending data to your device, end the transmission by setting SS high:

Arduino

1

digitalWrite(ss,HIGH);

Sending data is quite simple. Generally the most difficult part for people is interpreting the device data sheet to understand how commands and data need to be structured for transmission. But with some practice, these small hurdles can be overcome.

Now for some practical examples!

Time to get on the SPI bus and control some devices. By following the examples below, you should gain a practical understanding of how the SPI bus and devices can be used with our Arduino boards.

Example 34.1

Our first example will use a simple yet interesting part – a digital potentiometer (we also used one in the I2C tutorial). This time we have a Microchip MCP4162-series 10k rheostat:

Here is the data sheet.pdf for your perusal. To control it we need to send two bytes of data – the first byte is the control byte, and thankfully for this example it is always zero (as the address for the wiper value is 00h [see table 4-1 of the data sheet]). The second byte is the the value to set the wiper, which controls the resistance. So to set the wiper we need to do three things in our sketch…

// our MCP4162 requires data to be sent MSB (most significant byte) first

}

voidsetValue(intvalue)

{

digitalWrite(ss,LOW);

SPI.transfer(0);// send command byte

SPI.transfer(value);// send value (0~255)

digitalWrite(ss,HIGH);

}

voidloop()

{

for(inta=0;a<256;a++)

{

setValue(a);

delay(del);

}

for(inta=255;a>=0;--a)

{

setValue(a);

delay(del);

}

}

Now to see the results of the sketch. In the following video clip, a we run up through the resistance range and measure the rheostat value with a multimeter:

Before moving forward, if digital potentiometers are new for you, consider reading this short guide written by Microchip about the differences between mechanical and digital potentiometers.

Example 34.2

In this example, we will use the Analog Devices AD5204 four-channel digital potentiometer (data sheet.pdf). It contains four 10k ohm linear potentiometers, and each potentiometer is adjustable to one of 256 positions. The settings are volatile, which means they are not remembered when the power is turned off. Therefore when power is applied the potentiometers are all pre set to the middle of the scale. Our example is the SOIC-24 surface mount example, however it is also manufactured in DIP format as well.

To make life easier it can be soldered onto a SOIC breakout board which converts it to a through-hole package:

In this example, we will control the brightness of four LEDs. Wiring is very simple. Pinouts are in the data sheet.pdf.