Introducing Goldilocks – the Arduino Uno-compatible with 1284p and uSD card
[Update 19/03/2013 - the project is now fully funded. When the boards arrive we'll do a full review]
Introduction
It’s a solid fact that there are quite a few variations on the typical Arduino Uno-compatible board. You can get them with onboard wireless, GSM, Zigbee and more – however all with their own issues and specific purposes. But what if you wanted a board that was physically and electrically compatible with an Arduino Uno – but with much more SRAM, more EEPROM, more flash, more speed – and then some? Well that (hopefully) will be a possibility with the introduction of the “Goldilocks” board on Pozible by Phillip Stevens.
What’s Pozible?
Pozible is the Australian version of Kickstarter. However just like KS anyone with a credit card or PayPal can pledge and support projects.
What’s a Goldilocks board?
It’s a board based around the Atmel ATmega1284p microcontroller in an Arduino Uno-compatible physical board with a microSD card socket and a few extras. The use of the ’1284p gives us the following advantages over the Arduino Uno, including:
- 16 kByte SRAM = 8x Uno SRAM – so that’s much more space for variables used in sketches – great for applications that use larger frame buffers such as Ethernet and image work;
- 2 kByte EEPROM = 2 x Uno EEPROM – giving you more space for non-volatile data storage on the main board;
- 128 kByte flash memory = 4 x Uno – giving you much, much more room for those larger sketches;
- Two programmable USARTS – in other words, two hardware serial ports – no mucking about with SoftwareSerial and GSM or GPS shields;
- Timer 3 – the ’1284p microcontroller has an extra 16-bit timer – timer 3, that is not present on any other ATmega microcontroller. Timer 3 does not have PWM outputs (unlike Timer 0, Timer 1, and Timer 2), and therefore is free to use as a powerful internal Tick counter, for example in a RTOS. freeRTOS has already been modified to utilise this Timer 3;
- JTAG interface – yes – allowing more advanced developers the opportunity to debug their code;
- better PWM access – the 1284p brings additional 8-bit Timer 2 PWM outputs onto PD, which creates the option for 2 additional PWM options on this port. It also removes the sharing of the important 16-bit PWM pins with the SPI interface, by moving them to PD4 & PD5, thus simplifying interface assignments;
- Extra I/O pins – the 1284p has additional digital I/O pins on the PB port. These pins could be utilised for on-board Slave Select pins (for example), without stealing on-header digital pins and freeing the Arduino Pin 10 for Shield SPI SS use exclusively;
Furthermore the following design improvements over an Arduino Uno:
- adding through-holes for all I/O – allowing you to solder directly onto the board whilst keeping header sockets;
- replicate SPI and I2C for ease of use;
- microSD card socket – that’s a no-brainer;
- link the ATmega16u2 and ATmega1284p SPI interfaces – this will allow the two devices to work in concert for demanding multi-processing applications, involving USB and other peripherals;
- Fully independent analogue pins, including seperate AVCC and GND – helps reduce noise on the ADC channels for improved analogue measurement accuracy;
- move the reset button to the edge of the board – another no-brainer
- clock the board at 20 MHz – that’s an extra 4 MHz over a Uno. And the use of a through hole precision crystal (not a SMD resonator) allows the use of after market timing choices, eg 22.1184 MHz for more accurate UART timings.
What does it look like?
At the moment the board mock-up looks like this:
If funding is successful (and we hope it will be) the Goldilocks will be manufactured by the team at Freetronics. Apart from being a world-leader in Arduino-compatible hardware and systems, they’re the people behind the hardware for Ardusat and more – so we know the Goldilocks will be in good hands.
Will it really be compatible?
Yes – the Goldilocks will be shipped pre-programmed with an Arduino compatible boot-loader, and the necessary Board description files will be available to provide a 100% compatible Arduino IDE experience.
Conclusion
If you think this kind of board would be useful in your projects, you want to support a good project – or both, head over to Pozible and make your pledge. And for the record – I’ve put my money where my mouth is
Please note that I’m not involved in nor responsible for the Goldilocks project, however I’m happy to promote it as a worthwhile endeavour. 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.
Project: Clock Four – Scrolling text clock
Introduction
Time for another instalment in my highly-irregular series of irregular clock projects. In this we have “Clock Four” – a scrolling text clock. After examining some Freetronics Dot Matrix Displays in the stock, it occurred to me that it would be neat to display the time as it was spoken (or close to it) – and thus this the clock was born. It is a quick project – we give you enough to get going with the hardware and sketch, and then you can take it further to suit your needs.
Hardware
You’ll need three major items – An Arduino Uno-compatible board, a real-time clock circuit or module using either a DS1307 or DS3232 IC, and a Freetronics DMD. You might want an external power supply, but we’ll get to that later on.
The first stage is to fit your real-time clock. If you are unfamiliar with the operation of real-time clock circuits, check out the last section of this tutorial. You can build a RTC circuit onto a protoshield or if you have a Freetronics Eleven, it can all fit in the prototyping space as such:
If you have an RTC module, it will also fit in the same space, then you simply run some wires to the 5V, GND, A4 (for SDA) and A5 (for SCL):
By now I hope you’re thinking “how do you set the time?”. There’s two answers to that question. If you’re using the DS3232 just set it in the sketch (see below) as the accuracy is very good, you only need to upload the sketch with the new time twice a year to cover daylight savings (unless you live in Queensland). Otherwise add a simple user-interface – a couple of buttons could do it, just as we did with Clock Two. Finally you just need to put the hardware on the back of the DMD. There’s plenty of scope to meet your own needs, a simple solution might be to align the control board so you can access the USB socket with ease – and then stick it down with some Sugru:
With regards to powering the clock – you can run ONE DMD from the Arduino, and it runs at a good brightness for indoor use. If you want the DMD to run at full, retina-burning brightness you need to use a separate 5 V 4 A power supply. If you’re using two DMDs – that goes to 8 A, and so on. Simply connect the external power to one DMD’s terminals (connect the second or more DMDs to these terminals):

The Arduino Sketch
You can download the sketch from here. It was written only for Arduino v1.0.1. The sketch has the usual functions to set and retrieve the time from DS1307/3232 real-time clock ICs, and as usual with all our clocks you can enter the time information into the variables in void setup(), then uncomment setDateDs1307(), upload the sketch, re-comment setDateDs1307, then upload the sketch once more. Repeat that process to re-set the time if you didn’t add any hardware-based user interface.
Once the time is retrieved in void loop(), it is passed to the function createTextTime(). This function creates the text string to display by starting with “It’s “, and then determines which words to follow depending on the current time. Finally the function drawText() converts the string holding the text to display into a character variable which can be passed to the DMD.
And here it is in action:
Conclusion
This was a quick project, however I hope you found it either entertaining or useful – and another random type of clock that’s easy to reproduce or modify yourself. We’re already working on another one which is completely different, so stay tuned.
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.
Tutorial: Arduino and the MSGEQ7 Spectrum Analyzer
This is a tutorial on using the MSGEQ7 Spectrum Analyser with Arduino, and chapter forty-eight of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.
Updated 30/01/2013
In this article we’re going to explain how to make simple spectrum analysers with an Arduino-style board. (Analyser? Analyzer? Take your pick).
First of all, what is a spectrum analyser? Good question. Do you remember what this is?
It’s a mixed graphic equaliser/spectrum analyser deck for a hi-fi system. The display in the middle is the spectrum analyser, and roughly-speaking it shows the strength of different frequencies in the music being listened to – and looked pretty awesome doing it. We can recreate displays similar to this for entertainment and also as a base for creative lighting effects. By working through this tutorial you’ll have the base knowledge to recreate these yourself.
We’ll be using the MSGEQ7 “seven band graphic equaliser IC” from Mixed Signal Integration. Here’s the MSGEQ7 data sheet (.pdf). This little IC can accept a single audio source, analyse seven frequency bands of the audio, and output a DC representation of each frequency band. This isn’t super-accurate or calibrated in any way, but it works. You can get the IC separately, for example:
and then build your own circuit around it… or like most things in the Arduino world – get a shield. In this case, a derivative of the original Bliptronics shield by Sparkfun. It’s designed to pass through stereo audio via 3.5mm audio sockets and contains two MSGEQ7s, so we can do a stereo analyser:
As usual Sparkfun have saved a few cents by not including the stackable header sockets, so you’ll need to buy and solder those in yourself. There is also space for three header pins for direct audio input (left, right and common), which are useful – so if you can add those as well.
So now you have a shield that’s ready for use. Before moving forward let’s examine how the MSGEQ7 works for us. As mentioned earlier, it analyses seven frequency bands. These are illustrated in the following graph from the data sheet:
It will return the strengths of the audio at seven points – 63 Hz, 160 Hz, 400 Hz, 1 kHz, 2.5 kHz, 6.25 kHz and 16 kHz – and as you can see there is some overlap between the bands. The strength is returned as a DC voltage – which we can then simply measure with the Arduino’s analogue input and create a display of some sort. At this point audio purists, Sheldonites and RF people might get a little cranky, so once again – this is more for visual indication than any sort of calibration device.
However as an 8-pin IC a different approach is required to get the different levels. The IC will sequentially give out the levels for each band on pin 3- e.g. 63 Hz then 160 Hz then 400 Hz then 1 kHz then 2.5 kHz then 6.25 kHz then 16 kHz then back to 63 Hz and so on. To start this sequence we first reset the IC by pulsing the RESET pin HIGH then low. This tells the IC to start at the first band. Next, we set the STROBE pin to LOW, take the DC reading from pin 3 with analogue input, store the value in a variable (an array), then set the STROBE pin HIGH. We repeat the strobe-measure sequence six more times to get the rest of the data, then RESET the IC and start all over again. For the visual learners consider the diagram below from the data sheet:
To demonstrate this process, consider the function
readMSGEQ7()
in the following example sketch (download):
// Example 48.1 - tronixstuff.com/tutorials > chapter 48 - 30 Jan 2013 // MSGEQ7 spectrum analyser shield - basic demonstration
int strobe = 4; // strobe pins on digital 4 int res = 5; // reset pins on digital 5
int left[7]; // store band values in these arrays int right[7];
int band;
void setup()
{
Serial.begin(115200);
pinMode(res, OUTPUT); // reset
pinMode(strobe, OUTPUT); // strobe
digitalWrite(res,LOW); // reset low
digitalWrite(strobe,HIGH); //pin 5 is RESET on the shield
}
void readMSGEQ7()
// Function to read 7 band equalizers
{
digitalWrite(res, HIGH);
digitalWrite(res, LOW);
for(band=0; band <7; band++)
{
digitalWrite(strobe,LOW); // strobe pin on the shield - kicks the IC up to the next band
delayMicroseconds(30); //
left[band] = analogRead(0); // store left band reading
right[band] = analogRead(1); // ... and the right
digitalWrite(strobe,HIGH);
}
}
void loop()
{
readMSGEQ7();
// display values of left channel on serial monitor
for (band = 0; band < 7; band++)
{
Serial.print(left[band]);
Serial.print(" ");
}
Serial.println();
// display values of right channel on serial monitor
for (band = 0; band < 7; band++)
{
Serial.print(right[band]);
Serial.print(" ");
}
Serial.println();
}
If you follow through the sketch, you can see that it reads both left- and right-channel values from the two MSGEQ7s on the shield, then stores each value in the arrays left[] and right[]. These values are then sent to the serial monitor for display – for example:
If you have a function generator, connect the output to one of the channels and GND – then adjust the frequency and amplitude to see how the values change. The following video clip is a short demonstration of this – we set the generator to 1 kHz and adjust the amplitude of the signal. To make things easier to read we only measure and display the left channel:
Keep an eye on the fourth column of data – this is the analogRead() value returned by the Arduino when reading the 1khz frequency band. You can also see the affect on the other bands around 1 kHz as we increase and decrease the frequency. However that wasn’t really visually appealing – so now we’ll create a small and large graphical version.
First we’ll use an inexpensive LCD, the I2C model from akafugu reviewed previously. To save repeating myself, also review how to create custom LCD characters from here.
With the LCD with have two rows of sixteen characters. The plan is to use the top row for the levels, the left-channel’s on … the left, and the right on the right. Each character will be a little bar graph for the level. The bottom row can be for a label. We don’t have too many pixels to work with, but it’s a compact example:
We have eight rows for each character, and the results from an analogueRead() fall between 0 and 1023. So that’s 1024 possible values spread over eight sections. Thus each row of pixels in each character will represent 128 “units of analogue read” or around 0.63 V if the Arduino is running from true 5 V (remember your AREF notes?). The sketch will again read the values from the MSGEQ7, feed them into two arrays – then display the required character in each band space on the LCD.
Here’s the resulting sketch (download):
// Example 48.2 - tronixstuff.com/tutorials > chapter 48 - 30 Jan 2013 // MSGEQ7 spectrum analyser shield and I2C LCD from akafugu
// for akafugu I2C LCD #include #include "TWILiquidCrystal.h" LiquidCrystal lcd(50);
// create custom characters for LCD
byte level0[8] = { 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b11111};
byte level1[8] = { 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b11111, 0b11111};
byte level2[8] = { 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b11111, 0b11111, 0b11111};
byte level3[8] = { 0b00000, 0b00000, 0b00000, 0b00000, 0b11111, 0b11111, 0b11111, 0b11111};
byte level4[8] = { 0b00000, 0b00000, 0b00000, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111};
byte level5[8] = { 0b00000, 0b00000, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111};
byte level6[8] = { 0b00000, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111};
byte level7[8] = { 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111};
int strobe = 4; // strobe pins on digital 4 int res = 5; // reset pins on digital 5
int left[7]; // store band values in these arrays int right[7];
int band;
void setup()
{
Serial.begin(9600);
// setup LCD and custom characters
lcd.begin(16, 2);
lcd.setContrast(24);
lcd.clear();
lcd.createChar(0,level0); lcd.createChar(1,level1); lcd.createChar(2,level2); lcd.createChar(3,level3); lcd.createChar(4,level4); lcd.createChar(5,level5); lcd.createChar(6,level6); lcd.createChar(7,level7);
lcd.setCursor(0,1);
lcd.print("Left");
lcd.setCursor(11,1);
lcd.print("Right");
pinMode(res, OUTPUT); // reset pinMode(strobe, OUTPUT); // strobe digitalWrite(res,LOW); // reset low digitalWrite(strobe,HIGH); //pin 5 is RESET on the shield }
void readMSGEQ7()
// Function to read 7 band equalizers
{
digitalWrite(res, HIGH);
digitalWrite(res, LOW);
for( band = 0; band < 7; band++ )
{
digitalWrite(strobe,LOW); // strobe pin on the shield - kicks the IC up to the next band
delayMicroseconds(30); //
left[band] = analogRead(0); // store left band reading
right[band] = analogRead(1); // ... and the right
digitalWrite(strobe,HIGH);
}
}
void loop()
{
readMSGEQ7();
// display values of left channel on LCD
for( band = 0; band < 7; band++ )
{
lcd.setCursor(band,0);
if (left[band]>=895) { lcd.write(7); } else
if (left[band]>=767) { lcd.write(6); } else
if (left[band]>=639) { lcd.write(5); } else
if (left[band]>=511) { lcd.write(4); } else
if (left[band]>=383) { lcd.write(3); } else
if (left[band]>=255) { lcd.write(2); } else
if (left[band]>=127) { lcd.write(1); } else
if (left[band]>=0) { lcd.write(0); }
}
// display values of right channel on LCD
for( band = 0; band < 7; band++ )
{
lcd.setCursor(band+9,0);
if (right[band]>=895) { lcd.write(7); } else
if (right[band]>=767) { lcd.write(6); } else
if (right[band]>=639) { lcd.write(5); } else
if (right[band]>=511) { lcd.write(4); } else
if (right[band]>=383) { lcd.write(3); } else
if (right[band]>=255) { lcd.write(2); } else
if (right[band]>=127) { lcd.write(1); } else
if (right[band]>=0) { lcd.write(0); }
}
}
If you’ve been reading through my tutorials there isn’t anything new to worry about. And now for the demo, with sound -
That would look great on the side of a Walkman, however it’s a bit small. Let’s scale it up by using a Freetronics Dot Matrix Display - you may recall these from Clock One. For some background knowledge check the review here. Don’t forget to use a suitable power supply for the DMD – 5 V at 4 A will do nicely. The DMD contains 16 rows of 32 LEDs. This gives us twice the “resolution” to display each band level if desired. The display style is subjective, so for this example we’ll use a single column of LEDs for each frequency band, with a blank column between each one.
We use a lot of line-drawing statements to display the levels, and clear the DMD after each display. With this and the previous sketches, there could be room for efficiency – however I write these with the beginner in mind. Here’s the sketch (download):
// Example 48.3 - tronixstuff.com/tutorials > chapter 48 - 30 Jan 2013 // MSGEQ7 spectrum analyser shield with a Freetronics DMD
// for DMD #include // for DMD #include // SPI.h must be included as DMD is written by SPI (the IDE complains otherwise) #include #include "SystemFont5x7.h" // keep next two lines if you want to add some text #include "Arial_black_16.h" DMD dmd(1, 1); // creates instance of DMD to refer to in sketch
void ScanDMD() // necessary interrupt handler for refresh scanning of DMD
{
dmd.scanDisplayBySPI();
}
int strobe = 4; // strobe pins on digital 4 int res = 5; // reset pins on digital 5
int left[7]; // store band values in these arrays int right[7];
int band;
void setup()
{
// for DMD
//initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
Timer1.initialize( 5000 ); //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
Timer1.attachInterrupt( ScanDMD ); //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
dmd.clearScreen( true ); //true is normal (all pixels off), false is negative (all pixels on)
// for MSGEQ7
pinMode(res, OUTPUT); // reset
pinMode(strobe, OUTPUT); // strobe
digitalWrite(res,LOW); // reset low
digitalWrite(strobe,HIGH); //pin 5 is RESET on the shield
}
void readMSGEQ7()
// Function to read 7 band equalizers
{
digitalWrite(res, HIGH);
digitalWrite(res, LOW);
for( band = 0; band < 7; band++ )
{
digitalWrite(strobe,LOW); // strobe pin on the shield - kicks the IC up to the next band
delayMicroseconds(30); //
left[band] = analogRead(0); // store left band reading
right[band] = analogRead(1); // ... and the right
digitalWrite(strobe,HIGH);
}
}
void loop()
{
int xpos;
readMSGEQ7();
dmd.clearScreen( true );
// display values of left channel on DMD
for( band = 0; band < 7; band++ )
{
xpos = (band*2)+1;
if (left[band]>=895) { dmd.drawLine( xpos, 15, xpos, 1, GRAPHICS_NORMAL ); } else
if (left[band]>=767) { dmd.drawLine( xpos, 15, xpos, 3, GRAPHICS_NORMAL ); } else
if (left[band]>=639) { dmd.drawLine( xpos, 15, xpos, 5, GRAPHICS_NORMAL ); } else
if (left[band]>=511) { dmd.drawLine( xpos, 15, xpos, 7, GRAPHICS_NORMAL ); } else
if (left[band]>=383) { dmd.drawLine( xpos, 15, xpos, 9, GRAPHICS_NORMAL ); } else
if (left[band]>=255) { dmd.drawLine( xpos, 15, xpos, 11, GRAPHICS_NORMAL ); } else
if (left[band]>=127) { dmd.drawLine( xpos, 15, xpos, 13, GRAPHICS_NORMAL ); } else
if (left[band]>=0) { dmd.drawLine( xpos, 15, xpos, 15, GRAPHICS_NORMAL ); }
}
// display values of right channel on DMD
for( band = 0; band < 7; band++ )
{
xpos = (band*2)+18;
if (right[band]>=895) { dmd.drawLine( xpos, 15, xpos, 1, GRAPHICS_NORMAL ); } else
if (right[band]>=767) { dmd.drawLine( xpos, 15, xpos, 3, GRAPHICS_NORMAL ); } else
if (right[band]>=639) { dmd.drawLine( xpos, 15, xpos, 5, GRAPHICS_NORMAL ); } else
if (right[band]>=511) { dmd.drawLine( xpos, 15, xpos, 7, GRAPHICS_NORMAL ); } else
if (right[band]>=383) { dmd.drawLine( xpos, 15, xpos, 9, GRAPHICS_NORMAL ); } else
if (right[band]>=255) { dmd.drawLine( xpos, 15, xpos, 11, GRAPHICS_NORMAL ); } else
if (right[band]>=127) { dmd.drawLine( xpos, 15, xpos, 13, GRAPHICS_NORMAL ); } else
if (right[band]>=0) { dmd.drawLine( xpos, 15, xpos, 15, GRAPHICS_NORMAL ); }
}
}
… and here it is in action:
Conclusion
At this point you have the knowledge to use the MSGEQ7 ICs to create some interesting spectrum analysers for entertainment and visual appeal – now you just choose the type of display enjoy the results.
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.
Internet-controlled relays with teleduino and Freetronics RELAY8:
This is chapter forty-seven of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.
Updated 24/11/2012
In this article we’re going to look at controlling relays over the Internet. In doing so you will then be able to turn almost anything on and off as long as you have http access on an Internet-enabled device. Why would you want to do this? Connect an outdoor light – and turn it on before arriving home. Control the power to your TV setup – then you can control childrens’ TV viewing at a whim. Control farm water pumps without getting out of the truck. We’ll break this down into two stages. First we’ll explain how the RELAY8: relay control shield works and control it locally, then control it remotely using the teleduino service. We will be using Arduino IDE v1.0.1.
This tutorial will assume you have an understanding from three other articles – so please have a quick read of I2C bus, the MCP23017 I/O expander and teleduino. But don’t panic – we’ll try and keep it simple here.
The RELAY8: shield
First – our relay shield. We’ll be using the Freetronics RELAY8: shield:
Using the RELAY8: you can control eight relays using the I2C bus and the MCP23017 I/O expander – which saves your digital outputs for other purposes. There are three hardware settings you need to consider when using the shield:
- Power – how will you power the relay coils?
- You can directly connect between 5 and 24V DC using the terminal block on the right-hand side of the shield – great for stronger relay coils.
- You can power the relay coils using power from the Arduino. So whatever power is going to the Arduino Vin can power the shield. To do this jumper the two pins next to the Vin shield connector. In doing so – you must check that the combined current draw of all your relays on at once will not exceed what is available to the Arduino. Usually OK when using solid-state relays, as most examples use around 15mA of current to activate. However double-check your relay specifications before doing so.
- You can also power the Arduino board AND the shield by feeding in external power to the shield and jumpering the two pins described above
- Which I2C address to use for each shield? By default it is 0×20. However you can alter the last three bits of the address by changing the jumpers at the bottom-left of the shield. Each jumper represents one bit of the bus address – no jumper means zero, and a jumper means one. So if you jumper ADDR0, the address will be 0×21 – etc. Using this method you can then stack up to eight shields – and control 64 relays!
- Are you using an Arduino Leonardo board? If so – your shield I2C pins aren’t A4/A5 – they’re over near the top of the board:
However this isn’t a problem. Solder in some header pins to the shield’s SCL/SDA holes (next to AREF). Then turn over the RELAY8: board and you will see some solder pads as shown below. With a thin knife, cut the copper tracks shown with the blue lines:
Doing this will redirect the I2C bus from the microcontroller to the correct pins at the top-left.
Once you have decided on your power and I2C-bus options, it’s time to connect the relays. Doing so is simple, just connect the + and – from the relay coil to the matching position on your RELAY8: shield, for example:
Today we’re just using prototyping wires, so when creating a permanent installation ensure the insulation reaches the terminal block. When working with relays you would use a diode across the coil to take care of back-EMF – however the shield has this circuitry, so you don’t need to worry about that at all. And if you’re wanting to control more than one shield – they stack nicely, with plenty of clearance between shields, for example:
Now to test the shield with a quick demonstration. Our sketch will turn on and off each relay in turn. We use the addressing format described in table 1.4 of the MCP23017 data sheet, The relays 1 to 8 are controlled by “bank A” of the MCP23017 – so we need to set that to output in our sketch, as shown below (download sketch):
// Example 47.1 #include "Wire.h" // for I2C bus #define I2C_ADDR 0x20 // 0x20 is the address with all jumpers removed
void setup()
{
Wire.begin(); // Wake up I2C bus
// Set I/O bank A to outputs Wire.beginTransmission(I2C_ADDR); Wire.write(0x00); // IODIRA register Wire.write(0x00); // Set all of bank A to outputs Wire.endTransmission(); }
int period = 500;
void loop()
{
byte relay = 1;
for (int i=1; i<9; i++)
{
// turn on relay
Wire.beginTransmission(I2C_ADDR);
Wire.write(0x12); // Select bank A
Wire.write(relay); // Send value to bank A
Wire.endTransmission();
delay(period);
// turn off all relays Wire.beginTransmission(I2C_ADDR); Wire.write(0x12); // Select bank A Wire.write(0); // Send value to bank A Wire.endTransmission(); delay(period); relay = relay * 2; // move to next relay } }
The sketch simply sends the values of 1, 2, 4, 8, 16, 32, 64 and 128 to the shield – each value in turn represents relays 1 to 8. We send 0 to turn off all the relays. Here’s a quick video showing it in action – the LEDs on the shield show the relay coil power status:
Now there is one small caveat – every time you send a new command to the MCP23017, it overwrites the status of the whole bank of pins. For example if relay 3 is on, and we send the value 2 – this will turn on relay 2 and turn off 3. Why? Because the values are converted to binary when heading down to the relay shield. So if we send 1, in binary this is:
00000001
which turns on relay 1 – and turns off relays 2 to 7. But then if we send 4 to turn on relay 3, in binary this is:
00000100
which turns on relay 3, but turns off relays 1, 2, and 4 to 8. So how do we turn on or off all eight relays at once? Just do a little binary to decimal conversion. Let’s say you want relays 1, 3, 5 and 7 on – and 2, 4, 6 and 8 off. In binary our command value would be:
01010101
and in decimal this is 85. Want to turn them all on at once? Send 255. Then all off? Send zero.
Now let’s do it via the Internet…
You’re going to need an Ethernet-enabled Arduino board. This could involve adding an Ethernet shield to your existing board, or using an all-in-one board like the Freetronics EtherTen. We will now use the teleduino service created by Nathan Kennedy to send commands to our Arduino boards via the Internet. At this point, please review and understand the teleduino article – then, when you can successfully control a digital output pin – return here to continue.
First, get the hardware together. So ensure your relay shield is in the Arduino and you have uploaded the
TeleduinoEthernetClientProxy.ino
sketch. For the first couple of times, it’s good to still have the teleduino status LED connected – just to keep an eye on it. Plug your Arduino into your router and the power. After it connects to teleduino (four blinks of the status LED) we have to send three commands via http. The first tells teleduino that we’re sending I2C commands. You only do this once after every Arduino reset or power-up situation. It is:
https://us01.proxy.teleduino.org/api/1.0/328.php?k=999999r=defineWire
Remember to replace 999999 with your teleduino key. Then we send:
https://us01.proxy.teleduino.org/api/1.0/328.php?k=999999&r=setWire&address=32&bytes=%00%00
At this stage the relay shield is now ready to accept your bytes to turn on and off the outputs. Again, just like the sketch – we send two bytes. For example:
https://us01.proxy.teleduino.org/api/1.0/328.php?k=999999&r=setWire&address=32&bytes=%12%FF
turns on all the outputs – however with the URL we need to send the byte representing the outputs in hexadecimal. So 255 is FF, 0 is 0, etc. For example to turn them all off, use:
https://us01.proxy.teleduino.org/api/1.0/328.php?k=999999&r=setWire&address=32&bytes=%12%00
or to turn on outputs 1, 2, 3 and 4 use:
https://us01.proxy.teleduino.org/api/1.0/328.php?k=999999&r=setWire&address=32&bytes=%12%0F
Simple. You can simply bookmark your URLs for later use as well – and don’t forget to use a URL-shortener such as bit.ly to makes things simpler for you.
Conclusion
Now you have a way to control many relays either locally or remotely over the Internet. I hope you found this article useful or at least interesting. If you have any suggestions for further articles (and not thinly-veiled methods of asking me to do your work for you…) – email them to john at tronixstuff dot com. Thanks to Freetronics for the use of their hardware and Nathan Kennedy for teleduino, his support and advice.
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.
First Look – the Arduino Leonardo
Introduction
Recently the Arduino Leonardo was released, and I’ve finally got my hands on one. Some have claimed that the Leonardo as the successor to the Arduino Uno board, however that is somewhat subjective. In this article we have a look for ourselves and examine the differences between the Uno boards that we’re used to and the new Leonardo.
The board
Here it is unwrapped from the cardboard packet:
It uses the same physical footprint as the Uno, so no surprises there:
Now to travel around the board and see what’s new. First is the microcontroller – we have the Atmel ATmega32U4:
There are several pros and cons to using the 32U4. The pros include:
- More analogue inputs. As well as the usual A0~A5, digital pins 4,6,8,9,10 and 12 can be configured as A6~A11
- It handles USB. So no more external USB controller MCU or the old FTDI chip. Supposedly this saves money, however the retail price in some markets don’t reflect this
- More PWM pins – well one more. They’re now on D3, 5, 6, 9, 10, 11 and 13
- There is a little more SRAM than the Uno, it is now 2.5 kB
- SPI has moved – they’re now wired to the ICSP pins. So you now have D10~D13 seperate to SPI
- SPI has moved – they’re now wired to the ICSP pins. So if you have any shields that use SPI – too bad, they’re out. The most common example of this will be Ethernet shields – you’ll need to modify them with some jumper leads to contact the ICSP pins
- I2C has moved over to D2+3. So if you have any shields using I2C – they’ll need to be modified
- Less flash memory – the bootloader uses 4 kB of the 32 kB flash (the Uno used 0.5 kB)
However you can get an adaptor shield to use older Arduino shields with the Leonardo.
Since the Leonardo does not have a dedicated chip to handle serial communication, it means that the serial port is virtual– it’s a software routine, both on your operating system, and on the Leonardo itself. Just as your computer creates an instance of the serial port driver when you plug in any Arduino, the Leonardo creates a serial instance whenever it runs its bootloader. The Leonardo is an instance of USB’s Connected Device Class (CDC) driver.
This means that every time you reset the board, the Leonardo’s USB serial connection will be broken and re-established. The Leonardo will disappear from the list of serial ports, and the list will re-enumerate. Any program that has an open serial connection to the Leonardo will lose its connection. This is in contrast to the Arduino Uno, with which you can reset the main processor (the ATmega328P) without closing the USB connection (which is maintained by the secondaryATmega8U2 or ATmega16U2 processor).
There are some other changes to the board. Moving on, the next change is the USB socket. Do you recognise this socket?
Yes – micro USB. Thankfully (!) a growing number of mobile phones use this type for charging and USB connection, so you may already have a matching cable. Note that the Leonardo doesn’t include a cable, so if you’re an iPhone user – order yourself a cable with your Leonardo.
Next, the LEDs have been moved to the edge of the board. You can see them in the above image to the right of the USB socket. No more squinting through shields at strange angles to check the TX/RX lights. However this isn’t a new invention, our friends at Freetronics have been doing this for some time. Furthermore, the reset button has been moved to the corner for easier access.
There are also seperate connectors for the I2C bus – next to AREF, which should make modifying existing shields a little easier:
Finally, due to the reduction in components and shift to SMD – there is what could almost be called a large waste of space on the board:
A few extra user LEDs wouldn’t have been a bad idea, or perhaps circuitry to support Li-Po rechargeable batteries. However the argument will be “that’s what a protoshield is for”. Just saying… As for the rest of the hardware, the specifications can be found here.
Finally, the Leonardo is available in two versions – with and without headers. This makes it easier to embed the Leonardo into fixed applications as you can directly solder to the various I/O pins. An alternative to this would instead be the Freetronics LeoStick, as it is much smaller yet fully compatible.
Software
First – you need to drag yourself into Arduino IDE v1.0.1. Note you can run more than one version of the IDE on the same machine if you don’t mind sharing the same preferences file. Next, the Leonardo doesn’t reset when you open the serial monitor window (from arduino.cc) -
That means you won’t see serial data that’s already been sent to the computer by the board, including, for example, most data sent in the setup() function. This change means that if you’re using any Serial print(), println() or write() statments in your setup, they won’t show up when you open the serial monitor. To work around this, you can check to see if the serial port is open like so:
// while the serial stream is not open, do nothing:while (!Serial) ;
Using the 32U4, you also have two serial ports. The first is the emulated one via the USB, and the second is the hardware UART on digital pins 0 and 1. Furthermore, the Leonardo can emulate a USB keyboard and mouse – however with a few caveats. There is a section on the Leonardo homepage that you should really read and take note of. But this emulation does sound interesting, and we look forward to developing some interesting tools to take use of them, so stay tuned.
Conclusion
There is nothing wrong with the Leonardo board, it works as described. However you could consider this a virtual “line in the sand”, or a new beginning. Due to the changes in the pinouts shields will need to be redesigned, and for those of you still programming in Arduino v23 – it’s time to get up to speed with v1.0.1. If you need the special USB functions, keyboard and/or mouse emulation, or are happy with the changes and can get one for less than the cost of a Uno – great.
Here’s a video from the main man Massimo Banzi:
However if you’re looking for your first Arduino board – this isn’t the board for you right now. There are too many incompatible shields out there, and the inability to cheaply replace the microcontroller will see some beginners burn out their first couple of boards rendering them useless. Get yourself an Arduino Uno or compatible board such as the Freetronics Eleven.
In conclusion, classifying the Leonardo board as good or bad is not a simple decision. It may or may not be an improvement – depending on your needs. Right now – for beginners, this is not the board for you. For those who understand the differences between a Uno and Leonardo, sure – no problem. Frankly, I would get a LeoStick instead. At the end – it’s up to you to make an informed decision.
If you have any comments, leave them below. Thanks to Little Bird Electronics for the use of the Arduino Leonardo board.
Interact with Arduino over the Internet with Teleduino
Introduction
Recently a new method of interacting with an ethernet-enabled Arduino board and the Internet was brought to my attention – a new system called Teleduino. In this article we test a few of the basic features and see what is possible. Please note that these are my own experiments and that Teleduino is a work in progress. So follow along and see for yourself.
Getting Started
- You will need an Arduino Uno (or compatible) board and Ethernet shield with the Wiznet chip – or a Freetronics EtherTen (a much neater solution). Teleduino now supports Arduino Mega and the awesome EtherMega.
- Download and install the Teleduino Arduino library. This is available from the resources section of the home page. You will also need to be running Arduino IDE v1.0 or greater.
- Request an API key. This identified your particular Arduino from the rest.
- Get together some basic electronics components for testing, such as some LEDs and 560R resistors; sources of analog input such as an LDR or TMP36 temperature sensor; and a solderless breadboard.
- Don’t forget the ethernet cable from your Arduino stack to the router!
- Finally, some rudimentary knowledge about networking will be useful. (IP address, DHCP, etc.)
Controlling digital outputs
TeleduinoEthernetClientProxy.ino
which is included with the library examples. Before uploading, you need to make some modifications. The first of these is to add your API key. Go back to the email you received from Teleduino, and click on the link provided. It will take you to a website that shows a byte array variable named byte key[]. You will copy this into the sketch, replacing the same array full of hexadecimal zeros in the sketch – as shown below – with your own:
Next, scroll down to
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
… and change one of the hexadecimal numbers to 0×00… just in case there is a clash with other addresses on your network. You never know. Finally – depending on your network router, you may need to manually allocate the IP address for your Ethernet shield and/or set the DNS server to use. To do this, scroll down to
// User configurable variables
where you can change the useDHCP and/or useDNS variables to false, and update those values below. However if you’re not sure, just leave them be unless you need to change them. Finally – upload the sketch to your Arduino, get the hardware together and plug it into the network.
Watch your status LED – it will blink a number of times, depending on the status of things. The blink levels are:
- 1 blink – initialising
- 2 blinks – starting network connection
- 3 blinks – connecting to the Teleduino server
- 4 blinks – authentication successful
- 5 blinks – session already exists for supplied key (sometimes happens after a quick restart – will work on next auto-restart)
- 6 blinks – Invalid or unauthorised key – check your API key is correctly entered in the sketch as described earlier
- 10 blinks – connection dropped
If all is well, after a minute yours should be on blink level 4, then it will idle back to blink level 1. Now to test the connection with our first command.
You send commands to the Arduino using a set of URLs that will contain various parameters. You will need your API key again for these URLs which is then inserted into the URL. The first will report the version of software on the Arduino. Send
http://us01.proxy.teleduino.org/api/1.0/328.php?k=999999&r=getVersion
however replace 999999 with your API key (and in all examples shown here). If successful, you should see something similar to the following in the web browser:
However if something is wrong, or there are connection difficulties you will see something like:
Before using digital outputs, and after every reset of the Arduino) you need to set the pin mode for the digital output to control. In our example, we use:
http://us01.proxy.teleduino.org/api/1.0/328.php?k=999999&r=definePinMode&pin=6&mode=1
Note that the pin number and mode are set with single digits, as you can see above this is for pin 6, and we use mode=1 for output. You should save this as a bookmark to make life easer later on. When the command has been successfully sent, a message will be shown in the webpage, for example:
Moving forward – you turn the digital output on with the following:
http://us01.proxy.teleduino.org/api/1.0/328.php?k=999999&r=setDigitalOutput&pin=6&output=1
and to turn it off, set the final part of the URL to
output=0
Easy. How did you go? It really is amazing to see it work. Now you can control your Arduino from almost anywhere in the world. Again, saving these as bookmarks to make things easier, or a URL shortening service.
At this point you should now have the gist of the Teleduino service and how it is operated.
There is so much more you can do, and currently the list includes (From the author):
- Reset, ping, get version, get uptime, get free memory.
- Define pin modes, set digital outputs, set analog outputs, read digital inputs, read analog inputs, or read all inputs with a single API call.
- Define up to 2 ‘banks’ of shift registers. Each ‘bank’ can contain up to 32 cascaded shift registers, giving a total of 512 digital outputs.
- Shift register outputs can be set, or merged, and expire times can be set on merges (you could set an output(s) high for X number of milliseconds).
- Define, and read and write from serial port.
- Read and write from EEPROM.
- Define and position up to 6 servos.
- Set preset values for the above functions, which get set during boot. Preset values are stored in the first 160ish bytes of the EEPROM.
[22/09/2012] New! You can also control the I2C bus – check out this tutorial for more information.
For more information check the Teleduino web site, and further tutorials can be found here. Here is a simple example of Teleduino at work – controlling a light switch:
Conclusion
At this moment Teleduino is simple, works and makes a lot of ideas possible. We look forward to making more use of it in future projects, and hope you can as well. Kudos to Nathan Kennedy, and we look forward to seeing Teleduino advance and develop over the future. If all this Arduino is new to you, check out the tutorials. Thanks to Freetronics for the use of their Ethernet-enabled hardware.
April 2012 Competition Results
April is well and truly over so time to announce the results of our April 2012 Competition!
The winner of the First Prize is Michael F from Germany who will receive a new Freetronics DMD – Dot Matrix Display as reviewed recently and used in Clock One:
The DMD consists of 16 rows of 32 LEDs that can run directly from an Arduino-compatible board, or at a much higher brightness using an external power supply. It is simple to program for yet a load of fun to use. Specifications include:
- 32 x 16 high brightness Red LEDs (512 LEDs total) on a 10mm pitch
- 5V operation
- Viewable over 12 metres away
- Tough plastic frame
- Controller ICs on board, simple clocked data interface
- Arduino compatible library, graphics functions and example support
- Dimensions: 320(W) x 160(H) x 14(D)mm (30mm(D) including rear connectors)
DMDs are also available in blue, as shown below:
The winner of the Second Prize is Hendrik from Germany (!) who will receive one each of the eleven modules from the Freetronics Module/Sensor range, as reviewed recently:
With this range of modules you will be able to sense temperature, humidity, magnetic fields, light and sound pressure levels, sound and shock. Plus light up with the RGB LED, get more I/O with the expansion module, interface with the level shifter board, control high currents with the N-MOSFET, and power the lot with the tiny switch mode power supply. Available from Freetronics or a reseller near you.
For the curious, the questions and answers were:
- Name three HP calculators that use LED displays – There are many. Just scroll through the list available here.
- What does CPLD stand for? Complex programmable logic device. (Why CPLD? We were going to review some CPLD gear but it didn’t work out)
- In which year was Tektronix founded? 1946.
- Which company introduced the term “numitron”? RCA.
- Which company invented Bluetooth? Ericsson.
Thanks to Freetronics for the prizes!
In the meanwhile, 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.
Arduino and FFD51 Incandescent Displays
In this article we examine another style of vintage display technology – the incandescent seven-segment digital display. We are using the FFD51 by the IEE company (data sheet.pdf) – dating back to the early 1970s. Here is a close-up of our example:
You can see the filaments for each of the segments, as well as the small coiled ‘decimal point’ filament at the top-right of the image above. This model has pins in a typical DIP format, making use in a solderless breadboard or integration into a PCB very simple:
It operates in a similar manner to a normal light bulb – the filaments are in a vacuum, and when a current is applied the filament glows nicely. The benefit of using such as display is their brightness – they could be read in direct sunlight, as well as looking good inside. At five volts each segment draws around 30mA. For demonstration purposes I have been running them at a lower voltage (3.5~4V), as they are old and I don’t want to accidentally burn out any of the elements. Using these with an Arduino is very easy as they segments can be driven from a 74HC595 shift register using logic from Arduino digital out pins. (If you are unfamiliar with doing so, please read chapters four and five of my tutorial series). For my first round of experimenting, a solderless breadboard was used, along with the usual Freetronics board and some shift register modules:
Although the modules are larger than a DIP 74HC595, I like to use these instead. Once you solder in the header pins they are easier to insert and remove from breadboards, have the pinouts labelled clearly, are almost impossible to physically damage, have a 100nF capacitor for smoothing and a nice blue LED indicating power is applied.
Moving forward – using four shift register modules and displays, a simple four-digit circuit can be created. Note from the datasheet that all the common pins need to be connected together to GND. Otherwise you can just connect the outputs from the shift register (Q0~Q7) directly to the display’s a~dp pins.
Some of you may be thinking “Oh at 30mA a pin, you’re exceeding the limits of the 74HC595!”… well yes, we are. However after several hours they still worked fine and without any heat build-up. However if you displayed all eight segments continuously there may be some issues. So take care. As mentioned earlier we ran the displays at a lower voltage (3.5~4V) and they still displayed nicely. Furthermore at the lower voltage the entire circuit including the Arduino-compatible board used less than 730mA with all segments on – for example:
For the non-believers, here is the circuit in action:
Here is the Arduino sketch for the demonstration above (download):
// IED FF1 incandescent display demonstration // using four displays connected to four 74HC595s
int clockPin = 7; int latchPin = 8; int dataPin = 9; int dd=400;
// array for anodes (to display 0~9)
// the bits represent segments a~dp from left to right
// if you add one to the number (or turn on the last bit) the decimal point turns on
byte numbers[]={
B11111100, // digit zero
B01100000,
B11011010,
B11110010,
B01100110,
B10110110,
B10111110,
B11100000,
B11111110,
B11110110}; // digit nine
void setup()
{
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void allOn()
// turns on all segments of all displays. Used for testing
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 255); // digit 4
shiftOut(dataPin, clockPin, LSBFIRST, 255); // digit 3
shiftOut(dataPin, clockPin, LSBFIRST, 255); // digit 2
shiftOut(dataPin, clockPin, LSBFIRST, 255); // digit 1
digitalWrite(latchPin, HIGH);
}
void clearDigits()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 0);
shiftOut(dataPin, clockPin, LSBFIRST, 0);
digitalWrite(latchPin, HIGH);
}
void loop()
{
for (int a=0; a<10; a++)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, numbers[a]); // digit 4 (add 1 for decimal point)
shiftOut(dataPin, clockPin, LSBFIRST, numbers[a]); // digit 3
shiftOut(dataPin, clockPin, LSBFIRST, numbers[a]); // digit 2
shiftOut(dataPin, clockPin, LSBFIRST, numbers[a]); // digit 1
digitalWrite(latchPin, HIGH);
delay(dd);
}
for (int a=0; a<10; a++)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, numbers[a]+1); // digit 4 (add 1 for decimal point)
shiftOut(dataPin, clockPin, LSBFIRST, numbers[a]+1); // digit 3
shiftOut(dataPin, clockPin, LSBFIRST, numbers[a]+1); // digit 2
shiftOut(dataPin, clockPin, LSBFIRST, numbers[a]+1); // digit 1
digitalWrite(latchPin, HIGH);
delay(dd);
}
}
Now for the prototype of something more useful – another clock.
Time to once again pull out my Arduino-compatible board with onboard DS1307 real-time clock. For more information on the RTC IC and getting time data with an Arduino please visit chapter twenty of my tutorials. For this example we will use the first two digits for the hours, and the last two digits for minutes. The display will then rotate to showing the numerical day and month of the year – then repeat.
Operation is simple – just get the time from the DS1307, then place the four digits in an array. The elements of the array are then sent in reverse order to the shift registers. The procedure is repeated for the date. Anyhow, here is the sketch (download):
#include "Wire.h" #define DS1307_I2C_ADDRESS 0x68
// note the digital pins of the arduino that are connected to the nixie driver int clockPin = 7; int latchPin = 8; int dataPin = 9;
int clockArray[5]; // holds the digits to display int a=0;
// the bits represent segments a~dp from left to right
// if you add one to the number (or turn on the last bit) the decimal point turns on
byte numbers[]={
B11111100, // digit zero
B01100000,
B11011010,
B11110010,
B01100110,
B10110110,
B10111110,
B11100000,
B11111110,
B11110110}; // digit nine
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.send(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
}
// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
void setup()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
Wire.begin();
// Change these values to what you want to set your clock to. // You probably only want to set your clock once and then remove // the setDateDs1307 call.
second = 00; minute = 35; hour = 17; dayOfWeek = 5; dayOfMonth = 29; month = 4; year = 12; // setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); }
void showTime()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
if (hour<10)
{
clockArray[1]=0;
clockArray[2]=hour;
}
if (hour>9)
{
clockArray[1]=int(hour/10);
clockArray[2]=hour%10;
}
if (minute<10)
{
clockArray[3]=0;
clockArray[4]=minute;
}
if (minute>9)
{
clockArray[3]=int(minute/10);
clockArray[4]=minute%10;
}
displayArray();
}
void showDate()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
if (dayOfMonth<10)
{
clockArray[1]=0;
clockArray[2]=dayOfMonth;
}
if (dayOfMonth>10)
{
clockArray[1]=int(dayOfMonth/10);
clockArray[2]=dayOfMonth%10;
}
if (month<10)
{
clockArray[3]=0;
clockArray[4]=month;
}
if (month>10)
{
clockArray[3]=int(month/10);
clockArray[4]=month%10;
}
displayArray();
}
void displayArray()
// sends the data from clockArray[] to the shift registers
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, numbers[clockArray[4]]); // digit 4
shiftOut(dataPin, clockPin, LSBFIRST, numbers[clockArray[3]]); // digit 3
shiftOut(dataPin, clockPin, LSBFIRST, numbers[clockArray[2]]+1); // digit 2 and decimal point
shiftOut(dataPin, clockPin, LSBFIRST, numbers[clockArray[1]]); // digit 1
digitalWrite(latchPin, HIGH);
}
void loop()
{
showTime(); // display the time
delay(5000);
showDate(); // display the date (day and month) for two seconds
delay(2000);
}
and the clock in action:
So there you have it – another older style of technology dragged into the 21st century. If you enjoyed this article you may also like to read about vintage HP LED displays. Once again, I hope you found this article of interest. Thanks to the Vintage Technology Association website for background information.
April 2012 Competition
Welcome back!
Another month and time for another competition! First we’ll look at the prizes, and then examine the rules of entry.
First Prize is a new Freetronics DMD – Dot Matrix Display as reviewed recently and used in Clock One:
The DMD consists of 16 rows of 32 LEDs that can run directly from an Arduino-compatible board, or at a much higher brightness using an external power supply. It is simple to program for yet a load of fun to use. Specifications include:
- 32 x 16 high brightness Red LEDs (512 LEDs total) on a 10mm pitch
- 5V operation
- Viewable over 12 metres away
- Tough plastic frame
- Controller ICs on board, simple clocked data interface
- Arduino compatible library, graphics functions and example support
- Dimensions: 320(W) x 160(H) x 14(D)mm (30mm(D) including rear connectors)
The winner can select either a red DMD as shown in the video above or a blue one as such:
Second Prize consists of one each of the eleven modules from the Freetronics Module/Sensor range, as reviewed recently:
With this range of modules you will be able to sense temperature, humidity, magnetic fields, light and sound pressure levels, sound and shock. Plus light up with the RGB LED, get more I/O with the expansion module, interface with the level shifter board, control high currents with the N-MOSFET, and power the lot with the tiny switch mode power supply. Available from Freetronics or a reseller near you.
How to enter!
There will be five questions for you to answer spread across articles published between the 1st and 30th of April. At the end of April and once you have answers to all five questions, email the answers along with your full name, email address and postal address to competition at tronixstuff dot com with the subject heading April.
During the second week of May, all the correct entries will be collated and two randomly chosen. The first correct entry drawn will win first prize, and the second entry the second prize. Entries will be accepted until 05/05/2012 0005h GMT.
As with any other competition, there needs to be some rules:
- Incomplete entries will be rejected, so follow the instructions!
- The winners’ first name and country will be announced publicly;
- The winners’ name and mailing address will be passed to the prize supplier only for the purpose of prize delivery and not for any form of marketing.
- Entries that contain text not suitable for minors or insulting to the competition will be rejected (seriously – it happens);
- Prizes will be delivered via Australia Post domestic or regular international air mail. We take absolutely no responsibility for packages that go missing or do not arrive. If you live in an area with a “less than reliable” domestic postage system, you can pay for registered mail or other delivery service at your expense.
- Winners outside of Australia will be responsible for any taxes, fees or levies imposed by your local Governments (such as import levies, excise, VAT, etc.) upon importation of purchased goods;
- Prizes may take up to 45 days to be received;
- No disputes will be entered in to;
- Prizes carry no warranty nor guarantee – and are to be used or abused at entirely your own risk;
- Entries will be accepted until 05/05/2012 0005h GMT.
Thanks to Freetronics for the prizes!
In the meanwhile, have fun and keep an eye out for the four competition questions spread through the February posts… In the meanwhile, 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.
Results – February 2012 Competition
Now that February is over it’s time to announce the lucky winners of our February competition…
Prize One is a brand new Freetronics EtherMega board – the mother of all Arduino-compatible boards. As reviewed recently, the EtherMega combines the power and versatility of the Arduino Mega2560, a microSD card shield, a full Ethernet shield and power over Ethernet support:

Winner of the first prize is Rosemary H from the United Kingdom.
Prize Two is awesome – and a mystery no more. It is the new Freetronics LeoStick:
From the Freetronics website:
The LeoStick is just like the upcoming Arduino Leonardo, but given the “honey, I shrunk the kids” treatment!
Just pop it into your USB port (no cable required!) and upload straight from the Arduino IDE. We’ve even included on-board RGB LED lights and a speaker in this handy sized board. All the usual Arduino pins are present and each LeoStick comes with low profile header sockets for plugging in modules, shields and wires.
Winner of the second prize is Andrian from Moldova. Congratulations to the winners and thanks to everyone for entering.
For the curious, the questions and answers were:
- What frequency crystal would you use with the DS1307 RTC? – 32.768kHz
- How many LEDs are on an EtherMega board? Now I have two answers as the question should have been more specific. There are ten LEDs on the actual PCB, plus two more on the ethernet socket. So we accepted ten or twelve for the answer
- What are the dimensions (length x width) of an 0805 SMT component in mm? – 2.0 x 1.3 mm
- In what year was Ikea founded? – 1943
- What nationality is the Hakko company? Japanese
- Who came up with the name for the device known as the ‘transistor‘? - John R. Pierce
Once again, thanks to Freetronics for the EtherMega and LeoStick prizes!
In the meanwhile, 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.




































