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
VCC - VCC
GND - GND

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. http://shrimping.it/blog/shrimp/

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  http://bit.ly/1hscbh6 (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 ()
{
  Serial.begin(9600);
  pinMode(led, OUTPUT);   
}
void loop()
{
   Serial.println(led); // Output to the Serial Monitor the Arduino pin number so you can see it
   digitalWrite(led,HIGH);
   delay(1000);
   digitalWrite(led,LOW);
   delay(1000);
}


ArduinoPins.h

/*************************************************
 * 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