3-Wire LCD

LCD’s can use up quite some data lines on an arduino. Fortunately this can be reduced as most LCD’s can work in a 4 dataline mode. It can however done with even less datalines, using a shift register:

Backpack

I admit that I have been inspired by LadyAda’s ‘I2cSPI backpack’ but since I only needed the SPI mode and the pin lay-out of my LCD module was different from the LadyAda backpack. I decided to just make my own. To use this circuit one needs to install the proper LCD library.

The variable resistor can be replaced by the diode and R2. 0,65 is often the optimal voltage for the brightness. R1 and T1 are not really necessary if you do not have a backlit display (these usually come with 16 pins).

Interesting reading from Carlo Denaro can be found here. He uses  pin D10 (to 14+RS pin), D9 (to 12) and D8 (to 11)  and uses IC pin 2 for the Vlc.

More 3 wire solutions, and here

3 Wires still too many? Well, how about two wires, here too?  Some more circuits here

How about one-wire?

Identifying LCD modules

Recently I found an LCD module somewhere in one of my many boxes with things. As I had probably bought it over 20 years ago, but never used, I wasn’t quite sure anymore what the pin lay-out was.
lcd-2

Generally all these LCD modules, including this one, are based on the HD44780 chip. One could follow the lines of the SMD chip on the right of this picture and determine which pin of the connector, hooked up to which pin of the chip. Not too difficult with a small magnifying glass, but it seemed some of these tracks are under the chip, so that would be a small problem.

Now wouldn’t there be some general connection scheme? Well, yes, but there is a problem with that. There are basically two different lay-outs:

lcd3

Most of the connections between different modules are the same, but not always:

Pin Seiko M1632 Densitron LM22
1 D7 D7
2 D6 D6
3 D5 D5
4 D4 D4
5 D3 D3
6 D2 D2
7 D1 D1
8 D0 D0
9 E E
10 R/W R/W
11 RS RS
12 Vlc Vlc
13 Vss=Gnd Vdd=Vcc
14 Vdd=Vcc Vss=Gnd

As you can see, these two types differ on a very essential point: the connection for the power supply/ You do not want to mess with that. To make things even more complicated. The ‘official’ pin numbering for the Densitron is also the other way around, so what I labelled as ‘14’ is actually pin ‘1’ but for clearity’s sake I ‘normalized that in this comparison.
Also, just from looking at the LCD module you do not know what is the top or the bottom and therefore you also do not know if your connector is at the left or the right and thus you do not know what the pin numbering is to begin with, although fortunately in my case, they were numbered.

Add to that that in my LCD module some tracks were under the chip. I was going to need the datasheet of the chip:

hd44780

Compare that to my module:

lcd5

and many of the tracks can already be followed by the bare eye. It is easy to see that DB1 connects to the 4th pin on the right (which is pin 7, remember, you are looking at the back) DB0 connects to the 4th pin on the left (which is pin 8), etcetera etcetera. That all lines up with the table above. Unfortunately, the doubtful pins, the power supply pins, that should connect to the bottom 2 pins are obscure as they disappear under the chip. So, out comes the multimeter. I figured that pin 13 was the ground coz it’s track goes below the track of pin 14, which makes it very likely to connect to the Ground  pin, whereas pin 14 (if the board was designed intelligently) was much more suitable to connect to Vcc. As I hate putting multimeters on SMD pins (my eyes are not that good anymore) and it seemed the metal shield of the display was also attached to a copper track on the board, I measured between pin 13 and the metal shield/casing. Bingo! connected. With that I am pretty convinced that  this module follows the SEIKO M1632 lay-out and as a matter of fact, when looking for a picture of the SEIKO M1632  on the internet, it seemed quite similar to my module. In hindsight, the identification M1632 was even printed on the board, but almost invisible under another print: 7Y24127005
You may find datasheets  og the M1632 that give another layout of the pins. However, the following worked for me:
M1632

Now the only problem I have is that I wanted to connect it directly to a ‘Ladyada’ like ‘backpack’, but that is going to be difficult with this pin layout and I dont want to use a cable, just straight headers. Oh well, I guess I have to construct something myself then with a 595 chip.

More on these LCD’s

If you ever need to repair one, this may come in handy.

M1632 Datasheet

SD-card on Arduino

There are Arduino shields (like the modern Ethernet shield) that allow you to attach an SD card to your arduino. However if you are building a project that just needs a way to store data, then such a shield might be overkill.
It is possible to directly attacht an SD card to an Arduino and even then there is a cheap way and a more expensive elegant way.
The elegant way is to buy an SD card holder to solder on a circuitboard. These however come at a price.
Another way is to use the SD to microSD converter  that comes with most micro SD cards and use that one to solder to the circuitboard. Obviously that has a limitation as one then only can use micro SD cards and not the regular size SD cards.

SD card

The circuit in fact is pretty easy. other than ground and a powersupply line (3.3 V) you only need to connect 4 lines, 3 of which need a simple level adapter.

The Arduino SD library is very easy to use with easy to follow examples and it supports FAT16 and FAT32 file systems but note that it only supports one open file at a time and can only use short 8.3 file names.

For easy connection on a circuitboard consider soldering the pins to an angled header.

The resistors R1 – R7 can also be replaced by a 10k / 15k set and I have seen 1k8 and 3k3.
A better solution ofcourse would be to use a leveladaptor like a HEF4050 or an 74HC125 (such as in Lady Ada’s design)

With regard to Libraries that will work with this setup: There are 3 main libraries withint the Arduino development sphere:’SD’, ‘SDFat’ and ‘SDuFat’. These all should work. Just keep in mind that some of their examples still need the SSI pin (The chipselect) corrected because some boards will use pin 10, others will use pin 8 or pin 4.

If you are building this on breadboard and your connections might be a bit long, you may expect bus problems that will show up by e.g. problems with the initialization of the card. If that is the case. Try the example program of the SDuFat, as this library is one of the slowest. If that works, and the other library programs will still show problems, then at least you know that your card and connections are OK.

Then load the example sketch ‘SDinfo’  and find the line:

if (!card.init(SPI_HALF_SPEED, SdChipSelect)) {

change that to:

if (!card.init(SPI_SIXTEENTH_SPEED, SdChipSelect)) {

or

if (!card.init(SPI_QUARTER_SPEED, SdChipSelect)) {

and see if that will work. If it does, then your set up is OK but your wires are probably too long.

SDFatLib
SDUFat
SDUFAT-Hack
tinyFat

See also:

RS232 level converter for Arduino

The earlier circuit with an RS232 chip would have my preference  for connecting a self built Arduino to an RS232 port. However, if space is at a premium, a chip with 4 capacitors and a few resistors might just be too much. In that case a levelconverter made from discrete components might be a better choice.

levelconverter2

Just to make clear: The TX and RX in the circuit refer to the microcontroller. The Tx signal from the Arduino gets fed to T2 and send to pin 2 of the DB9. That Pin 2 is the receive signal from the PC. The TX signal from the PC is available on Pin 3. This gets fed into T1 who then feeds it to the Rx of the Arduino.

There is a slightly fancier version available:

But the first circuit worked well for me.

Yet another circuit, looks as follows:

With regard to R5 that can be connected to TxD to borrow a negative voltage, but the circuit will only work half duplex then. It can also be connected to ground, which will probably work with most RS232 ports and that will allow Full duplex

One thing you have to keep in mind with these circuits: The RS232 does not trigger an automatic reset of your microcontroller anymore. If you still wish to have that, add another transistor, akin to what is build around T1 and attach that with it’s base side to the CTS and with its collector side to the Reset on the microcontroller, via a 100nF capacitor

Bluetooth for Arduino (or other)

Dealextreme offers a cheap Bluetooth module that can be used to add bluetooth to an Arduino/Atmel project.
Connecting it is really simple as you can see in the below circuit.
As it is on a 3.3 Volt supply, in connevting it to a generally 5 volt TTL UART, you need to keep a couple of things in mind:
Connecting the Tx line directly to the Rx line of the UART is no problem, but for the Tx line coming from the UART you need a voltage adapter that is formed by the 5k6 and 10k resistors.
In order to get the Bluetooth model to work properly, it needs a reset signal that is taken from the Vcc.
Pins that are not used should be left not connected. Though the module has 34 pins, you only really need to connect 8 pins to establish communication and 4 of those are connections to ground.

bt-module

At first glance, soldering to the module may seem a bit daunting as it is real tiny. I decided to solder some small stiff wires to the cups that form the pins and stick these through some stripboard, raising the module a bit off of the stripboard. Another solution is to solder the module directly to the copperside of a PCB, but that needs some accurate etching. Just to make clear: Pin 3 and 4 don’t need to be connected to anything, but it might be handy to attach them to a 2 pin header that can be shorted in case that is needed.

Using the module is fairly simple: linvor
First establish if it actually works: after putting the circuit together, apply voltage supply and start up a bluetooth device such as a computer or a mobile phone and see if they can find it. It should come up as ‘linvor’  and asks for a pincode which is ‘1234’.

If you check the ‘services’  of the device it will report itself as a serial interface. The LED in the circuit is ON when there is a connection and it ‘blinks’ when there isn’t.
So if this all works, at least that is half of the worries done. Now you got to make sure if the serial interface is actually doing something. You can do that in various ways, but set your communication speed to 9600/8N1 Baud as that is the default baudrate of this chip:

  • Hook it up to a working arduino/atmel/pic controller and see if you can get connection (this one for instance). or
  • Hook it up to a computer’s serial port (but make sure you use a level adapter before you do that coz RS232 voltages will fry yr chip) and see if you can communicate (like sending AT commands). or
  • Connect the Rx and Tx of this circuit, establish a bluetooth connection through yr computer, use the Arduino IDE (select ‘no line ending) to send characters to the proper COM port and see if they get echoed. 

If any of these 3 work you are set to go.

The firmware
Though many of these models may look exactly the same (and in fact could be the same), they still may have different firmware. The Dealextreme module has linvor 1.5 firmware, als known as HC6. Other models may have HC5 firmware.
The HC5 firmware has a very limited AT instruction set:

It can check the settings, it can change the baudrate and parity and it can change the PIN code and the name:

Command Response Note
AT OK Just a check
AT+VERSION Linvor1.5 Firmware version
AT+BAUDx OKx Sets Baudrate
x=:
1 for 1200 baud
2 for 2400 baud
3 for 4800 baud
4 for 9600 baud
5 for 19200 baud
6 for 38400 baud
7 for 57600 baud
8 for 115200 baud
9 for 230400 baud
A for 460800 baud
B for 921600 baud
C for 1328400 baud
AT+NAMEstring OKsetname Set device name, 20 characters max
AT+PINxxxx OKsetpin Set PINcode. 1234 bij default
AT+Px OKsetparity Set the parity
x=:
N for None
E for even
O for Odd

 

With the HC6 firmware, there should be no LF or CR after the command. The module will interpret the command that is given within 1 second. As therefore you have 1 second to type the command, it might be better to cut and paste it from e.g. Notepad. Now how to get into AT setting is simple for the HC5 firmware. If the module has not paired with another bluetooth transceiver, it is in AT mode. You may need to connect the CTS and RTS pins and you may need to type ‘$$$’ first

HC5 Firmware
If you have a model with HC5 firmware, you need to do a bit more to get it in AT mode:

This firmware provides 2 ways to activate AT mode :

The first way:

  • set low level on PIN34
  • Supply power to the module
  • set high level on PIN34

Then the module will enter on AT mode with your configured baud rate (default : 9600 8N1)

The second way :

  • set high level on PIN34,
  • Supply power to the module

The module will ALWAYS enter in AT mode with a 38400 baud rate (8N1).
The second way is useful if you don’t remember your configured baud rate.
AT mode can be reached only when PIN34 is high.

Moreover sending AT commands is different from the HC06 firmware (Linvor). In HC05 firmware you have to send CR and LF after each command.

Sme useful AT commands :

  • AT\r\n AT test command should respond OK\r\n
  • AT+ROLE=1\r\n Set master mode
  • AT+ROLE=0\r\n Set slave mode
  • AT+VERSION?\r\n Get the firmware version
  • AT+UART=115200,1,2\r\n Set the baud rate to 115200
  • AT+PIO=10,1\r\n Set PIO10 to high level

Further information can be found in this documentation.

 

 

Simple Arduino

Arduino BasicAn arduino in its simplest form is an ATMEGA chip with bootloader, a crystal, 2 capacitors and reset switch. An LED on pin 13 and of course some possibilities to make easy connections are ‘nice to have’.

A simple circuit is found to the right. It is a small adaptation from Iñigo Zuluaga, who is a master in designing nifty circuits with a paper ‘silk screen’. Other people have done similar things like in the paperduino project van Guillherme Martins or the oomlaut arduino and also here.

The circuit is quite easy. Programs can be uploaded with either one of the many USB or serial connector boards or cables

The simple arduino, connected to a serial level converter
diy-arduino2

Serial connection for your Arduino / Atmega

A connection between a computer and a self build Arduino (or other microcontroller) is easy to make with a MAX232 chip. The figure below is an almost classic design. It is according to the october 2002 revision of the datasheet: C4 is connected between pin2 and earth, while in other designs it is connected between pin 2 and Vcc (kathode on Vcc). This circuit just worked for me. I guessed that if pin 2 has a higher potential than Vcc, it also has a higher potential than ground. In some circuits you will also find it connected between pin 2 and 6

In principle you could do with only 2 signals (Tx and Rd), but I have added a reset that is connected to the RTS signal on the subD connector (Via the Max232 of course) MAX232

Just for some clarification: Normally with a serial communication set up, the Tx signal of one device, is connected to the Rd pin of the other device. In this circuit, that is taken care of on the SubD connector: Pin 3 is the Tx signal, that goes to the RdIn (pin 8)  of the chip. It is converted in voltage in the chip, then goes to RdOut on pin 9. That pin –though called Rd-  then goes to the Rd pin on the Arduino/Atmega/Pic. The connection between Tx and Rd already has been made, no need to switch that again.
Same for the Tx signal of the microprocessor: It attaches to pin10 on the Max232, is converted and appears on pin 7 of the chip and then is brought to the Rd pin on the SubD connector. The DB9 plug in th epicture is a female plug looked at from the solder side.
If for any reason one would prefer to use an old SubD25 serial connector, the table below shows the corresponding pins between the two. To make things a bit confusing both pin 2 and 3 have exactly opposite functions on these connectors.

DB9 Signal DB25
1 DCD 8
2 Rd 3
3 Tx 2
4 DTR 20
5 SGnd 7
6 DSR 6
7 RTS 4
8 CTS 5
9 Ri 22

The LED’s and  resistors R3 and R4 are not really necessary, they just give a visual indication of the transmitting signals, choose a nice color.

R1 and R2 are in fact also not necessary, but they offer some form of protection should you wire up wrong (like connecting to the wrong pin on your microprocessor)

RS232 naar TTL op stripboard

Once the circuit is build, then first test it before you attach it to your Arduino. The easiest way to test it is to temporarily connect the Tx and Rd pin (so the ends of R1 and R2) with eachother. Apply 5 volts to the chip and connect your serial cable.

Open up the Arduino IDE, select the proper COM port under ‘Tools’, open up the serial monitor and type in some characters and click ‘Send’. The characters should be echo-ed back.

For me this worked with all baud-rates.

Then disconnect the temporary connection you just made and connect Tx and Rd to the corresponding pins on your board/chip.

If that has the bootloader installed, you should be able to upload a program to your board with this serial connection.

Worked like a charm

The finished circuit on stripboard. I opted for a 25DB connector rather than a 9DB connector because that fitted the serial cable I had. Don’t be confused by the double row of headers. Again, that is all I had but a single row would suffice
P1040253
The serial interface, connected to a simple arduino board
diy-arduino2

Note: Many ‘modern’ computers that  still have a serial connector do in fact already not work with the high voltages that we know from true RS232 and then the MAX232 might not be needed, but one could use a levelshifter as e.g. Sparkfun is selling ($6.95) and try to build that yourself. It is not a big circuit, but in my idea, usung the MAX232 is just easier and the RS232Shifter board is actually a bit of a hack and does not seem as reliable.

Lots of RS232 info here. and here

Another one here, and here, and here, and here, and here, and here (Thai)

Max 232

RS232-TTL