Wednesday, January 22, 2014

16x16 LED Matrix using MAX7219 from eBay for Arduino

Like a lot of people one of the first things I did with my Arduino was use it control an 8x8 LED Matrix and then get it to do fun things like scrolling messages and making little games. It's amazing what you can do inn 8x8.

Arduino Scrolling Message changed using Serial Monitor

Arduino 8x8 LED Racing Game

But going beyond 8x8 is not as easy as it seems due to trying to get the boards aligned and also just the sheer number of wires needed to connect all the driver ICs. From the video above for the Race Game you see there are a lot of wires just for an 8x8 if using a 74HC595 .

On one of my semi-regular trawl of eBay I came across the following.

It's 4 separate 8x8 LED modules with the MAX7219 driver IC included.  No great shakes there as these are all over eBay and anywhere else you want to buy electronics bits.
The difference is the last word in the description 'Cascade'  In the images and short video at the link they are shown in an 16x16 arrangement and if you look closely at the boards there are extra headers in each corner to facilitate the cascading.

Of course I had to buy a set which I'm waiting to be delivered. Slow boat from China. Could be a fun March when it arrives.

Tuesday, January 21, 2014

Reading IR Remote using TSOP1838 and Arduino Compatible Pro Mini

After getting the Arduino compatible Pro Mini all soldered up and programmed using the CP2102 serial adaptor I thought it would be see if it works with the TSOP1838 Infra Red Receiver.  I bought 2 from eBay as I want to rig up a couple of Arduinos to send and receive 'messages' from each other.

I started by testing with my Arduino Uno with Ethernet Shield attached. It was the nearest to hand so I thought I might as well see if the TSOP1838 works with it.
TSOP1838 on small board with pins for use with breadboard

After finding a blog post that explains the Pins are transposed.  From top to bottom in the picture above it is
OUT - connected ot digital pin on the Arduino

Compared to the actual pin outs for the PSOP1838 OUT and VCC are swapped.

Then as I expected I'm late to the party I checked if there was a handy library already in place to take if the decoding and I found the fantastic Ken Shirriff Library

Wired it all up correctly and used the library provided.
Uploaded the IRrecvDemo sketch provided with the library and when I pressed a button a remote control the LED on the IR board flashed so date was being received but nothing was appearing on the Serial Monitor.
I tried switching pins.
I added an extra Serial.prinln to output directly the logic on Pin 11 (default in the Example)
I looked at the code and noted it uses Interrupts

Then  I remembered the Ethernet Shield uses Interrupts. Maybe the Ethernet Shield is was stopping the IR Receiver from working.  So, off came the Ethernet Shield. Rewired the circuit. All 3 wires...and it worked perfectly and reliably.

Then it was onto seeing it it would work with the Pro Mini from eBay.

Wired OUTto Pin4. Note VCC middle and GND on the right above.
Wired it all up as per the programming blog post. Added the IR Receiver and uploaded the same sketch after remembering to change the board from Arduino Uno to Arduino Duemilanove w/ ATmega328.
This time it worked first time. No reconfiguring. No modification of the code.

It means for £1.18 (TSOP1838) and £2.15 (Pro Mini) a total of £3.33 I can read remote Infra Red Remote controls and with the simple addition of an IR LED and a resistor I can also send IR codes. I have IR LEDs somewhere in my box of wires, so a little hunt will be needed to find them. It will be fun to see if I can send codes to my TV.

NOTE: The Ken Shirriff Library includes codes to emulate various remote controls, so the library can handle send and receive.


Wednesday, January 15, 2014

ArduinoPins.h converts Atmega328 pins numbers to Arduino board pin numbers

I've been having fun with different Arduino compatible implementations including being part of a team that created an Arduino Shrimp based kit for the Brighton Maker Faire based on the details for The Shrimp.
The kit details, build instructions and code are available to download at the following link

When working with the raw ATmega328 chip the pin numbers do not match the Arduino pin numbers.  So, we had to continuousy translate between the 2 for the standard Arduino IDE to be used

Thinking about it today I thought it would be useful to have a .h file that converts the Atmega328 pin numbers to the Arduino pin numbers so I put together a little .h file with the conversion in it.

You can download the file ArduinoPins.h with the example code shown below at the following link (Google Drive link shortened)

// Example using library to convert Atmega328 pins to Arduino ID pins
#include "ArduinoPins.h"

int led = Atmega_P19;  // Atmega_P19 is the same as Arduino Pin 13

void setup ()
  pinMode(led, OUTPUT);   
void loop()
   Serial.println(led); // Output to the Serial Monitor the Arduino pin number so you can see it


 * Public Constants to convert Atmega pin numbers
 * to Arduino IDE pin numbers
 * Means no need to manually convert the pins

// Defintion for the Digital Pins
#define Atmega_P2    0  // RX
#define Atmega_P3    1  // TX
#define Atmega_P4    2
#define Atmega_P5    3  // PWM
#define Atmega_P6    4
#define Atmega_P11   5  // PWM
#define Atmega_P12   6  // PWM
#define Atmega_P13   7
#define Atmega_P14   8
#define Atmega_P15  9  // PWM
#define Atmega_P16  10  // PWM
#define Atmega_P17  11  // PWM
#define Atmega_P18  12
#define Atmega_P19  13

// Definition for Analog Pins
#define Atmega_P23  0
#define Atmega_P24  1
#define Atmega_P25  2
#define Atmega_P26  3
#define Atmega_P27  4
#define Atmega_P28  5

Tuesday, January 14, 2014

Programming the Arduino Pro Mini 16MHz 5V using a USB serial adaptor

Yesterday I soldered up my Arduino Pro Mini compatible board -

Today I wanted to figure out how to program it.

As I have made some bare bones Arduino compatibles using the Shrimp details from Morecombe Makers I've done some programming using serial and I know the USB serial adaptor I have works for raw programming.It's uses on the CP2102 chip.

A really useful thing with the board I have is that it has the DTR pin which can used to reset the Arduino and put it into programming mode.

USB Serial - pin out the side is DTR (essential)

I also know the USB board I have being a very cheap board has the TX and RX labelled wrongly as the standard is to cross over the wires. TX-RX and RX-TX but my one is a direct connection TX-TX and RX-RX.

With great confidence and knowing to wire from USB to Arduino as TX to TX and RX to RX, GND to GND, 5V to VCC and DTR to RST (to do the reset needed)

In the IDE I selected Arduino Duemilanove w/ ATmega328 as per the Arduino site

With everything correctly setup I uploaded a modified version of Blink so I can see the difference between the pre-programmed Blink.

It failed. No error message, it just didn't upload.

So, began the usual Google hunt and after looking at a bunch of pages detailing programming the boards using another Arduino I came across this YouTube video with the essential nugget of information that on the Arduino Pro Mini there is a pin on the right angle header labelled GRN in the corner next to the TX pin. I had no idea what it was so in the true hacker tradition I ignored it.  Ends up it's essential as this is where DTR needs to be connected as it is a Reset line but with the required capacitor to hold the reset long enough for the programmer to engage.  The video also gives extra details on different programmers and is well worth a watch..
Note: The video mentions that you could use the DTR or RST lines on the USB adaptor connected to GRN.  For me with my serial adaptor only DTR worked. RST on the USB adaptor did not work for putting the Arduino into programming mode.

Once the DTR line was connected to the GRN pin on the Arduino Pro Mini it programmed perfectly.

All wired up and working. The big breadboard is only
there to make it king of level

Now I have the board all soldered up I have to figure out something to do with it.maybe involving the capacitive touch pads I bought recently.

Soldering up Pro Mini Arduino compatible board bought from eBay

UPDATE: Link to blog post on programming the board using a CP2012 USB serial adaptor

I bought 2 Pro Mini Arduino Compatible boards from eBay (UK) at £2.15 each including shipping.

They are effectively functionally the same as an Arduino Uno but designed to be plugged into a breadboard. It came with male headers for both sides to go under the board to plug into the breadboard and a right angle connection for the serial connection at one end. If you look closely there are 2 pins (holes) at the bottom just above the main row for Analogue 4 & 5. Also, the near end has Analogue 6 and 7 as well as what I think are V++ and GND.
I decided that rather than leaving these pins disconnected  would add 3 x 2 pin female headers on the top of the board. So, I bought a bunch of headers from eBay for £1.84. It looks like they have gone up to about £2.64. Still for 10 x 40 male and female headers it’s still cheap.

Add a breadboard and some wires and you have a great prototyping setup.

These are nice little board with some strange design decisions like the 2 x 2 pin headers on the end and the 2 pins for A4 and A5. But by using the female headers it gets around these things. The alternative is to not include A4 and A5 if you don't need all 6 analogue inputs.

Here are some pictures from the build with comments.

Bits that came in the eBay order

Creating 2 pin female headers from 40 pin header

Snap off pins. 3rd will fall out. Clean up the edges to fit

3 x 2 pin female headers inserted in the top

3 x 2 pin headers from the bottom for soldering

3 x 2 pin headers soldered up and
right angle serial header in place for soldering

All soldered up and ready to be used

As a side note I also purchased a Leonardo Pro Micro ATmega32U4 Arduino for £3.30