For those who might not be aware, the Si5351 is a small, very stable, very inexpensive clock generator that is addressed and controlled over I2C. More on this later, after we design and build the other non-RF parts of the signal generator.At some point the project will migrate to one of the Arduino Micros I've received, but for now the dust has been knocked off the Diecimila.
The first part of the signal generator needs to be the LCD display, as the testing and implementing the remainder will be easier if I have a visual display to which the Arduino can write data.
When I considered the display, one of my concerns was the number of connections on the traditional LCD modules. Early on in my thinking I was considering eventually moving this project to an Adafruit Trinket or other micro-micro Atmel ATtiny85 board. Well, I believe that the number of pins required to communicate with an LCD module exceed the number of pins on the actual Trinket.
Thanks to I2C interfaces which many different vendors are implementing as add-on modules, I was able to reduce the need for seven or more pins to just four: Serial Data Line (SDA), Serial Clock Line (SCL), +5VDC, and GND. Since I2C is actually a data bus, this won't cause me problems when the time comes to integrate the Si5351 module which also uses I2C for control. For my Arduino, the SDA and SLC pins are on analog pins 4 and 5, but other Arduino models may differ; make sure you check the
I ended up with the Sainsmart 20x4 LCD Module with I2C backpack which came at a good price and is based on the well-established HD44780 LCD...well at least from the pocket book perspective. There are some problems with cheap hardware that aren't immediately evident. Documentation is terrible, and not just in the "poorly translated" variety of terrible, but in the wholly wrong information variety.
The standard Arduino LiquidCrystal library doesn't support I2C interfaced LCD modules, so off I go to find a compatible library. Thanks to Francisco Malpartida for his drop-in replacement to the standard library. It retains the core functions for the LiquidCrystal standard library and adds I2C and Shift Register interfaces.
In order to use an I2C slave on the bus the I2C master (Arduino) has to know the address of the slave device; without this, nothing can happen. The Sainsmart website for the product is what passes for the documentation on this product. They tell us that the address for the LCD module is 0x3F, so off that goes into my test code for the Arduino. No joy!
Poking around on the Internet long enough and I find out that correct addressing, or more specifically the vendor documentation of it, is a common problem with these new I2C backpacks. Turns out that this module runs at address 0x27 no 0x3F. One tool that helped me here was the ubiquitous I2C Scanner code that crawls the I2C address space looking for live slave devices. Run the sketch and I see:
I'm quite sure that this will be useful again, given my propensity forScanning...
I2C device found at address 0x27 !
done
One other annoyance was getting the backlight pin (one the HD44780 module) correctly identified for the code. No software to help here, I just experimentally changed the #define BACKLIGHT_PIN macro in the code until the LCD backlight stayed lit when the sketch ran. This particular LCD module was pin 3.
For those interested, I've pasted in the final code below which I came up with to test this setup.
Next step...rotary encoders for input and control.
UPDATE:
Looks like the code is completely portable to the Arduino Micro. No edits, nudges, or hits with a code hammer.
No comments:
Post a Comment