Propeller 1 and I2C LCD: Please Help
TheKaduu
Posts: 41
Hi experts,
I am new to Propeller. I am trying to convert my existing Arduino project to Propeller.
The project, in a nutshell, is a remote controlled boat that has two motors, two ESCs, 2 temperature sensors for motors, GPS, Xbee Pro and parallel lipos for the power...
Well, I also made a remote controller for the boat that uses Xbee to communicate. There is a joystick, linear pot for the speed and two I2C LCDs (I2C/TWI 20x4 white on blue from DFRobot). LCD will be displaying per cell voltages (boat and remote controller), motor temperatures and speed from the GPS...
Now, I have been using Arduino library provided by DFRobot which uses Wire library on Arduino. Everything works just fine. When I try to convert everything to Propeller, the only problem I have is the LCDs.
I have been using Michael Green's Basic_I2C_Driver v1.3 which was simple enough for a Propeller newbee like me. I have been using the following code to turn the backlight of the LCD which is the first step in the DFRobot library's LCD initialization. I will attach the DFRobot library files. Project wiring is described after the code.
Here is how I wired the project... I use 4 bi-directional voltage level converter from Adafruit between the Propeller ASC+ and LCD. LCD is powered by 5V and SCL and SDA pins are pulled up using 4.7k at the 3.3v side (which I think will be converted to 5V at the LCD side by the level converted... if not, please let me know)... It is also important to point out that I soldered the smd jumper in the back of the Propeller ASC+ for pin 0 and pin 1 as suggested at http://mghdesigns.com/wiki/asc:start
Why the backlight not turning off? What am I doing wrong? Can anyone help?
Thank you for your time and help,
TheKaduu
I am new to Propeller. I am trying to convert my existing Arduino project to Propeller.
The project, in a nutshell, is a remote controlled boat that has two motors, two ESCs, 2 temperature sensors for motors, GPS, Xbee Pro and parallel lipos for the power...
Well, I also made a remote controller for the boat that uses Xbee to communicate. There is a joystick, linear pot for the speed and two I2C LCDs (I2C/TWI 20x4 white on blue from DFRobot). LCD will be displaying per cell voltages (boat and remote controller), motor temperatures and speed from the GPS...
Now, I have been using Arduino library provided by DFRobot which uses Wire library on Arduino. Everything works just fine. When I try to convert everything to Propeller, the only problem I have is the LCDs.
I have been using Michael Green's Basic_I2C_Driver v1.3 which was simple enough for a Propeller newbee like me. I have been using the following code to turn the backlight of the LCD which is the first step in the DFRobot library's LCD initialization. I will attach the DFRobot library files. Project wiring is described after the code.
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 i2cSCLLine = 0 'SCL is on Propeller pin 0 i2cSDALine = 1 'SDA is on Propeller pin 1 LCD_Addr = $20 'Flags for backlight control LCD_BACKLIGHT = $08 LCD_NOBACKLIGHT = $00 'debug - USE onboard pins pcDebugRX = 31 pcDebugTX = 30 'serial baud rates pcDebugBaud = 115200 OBJ i2cObject : "Basic_I2C_Driver_1" debug : "Debug_PC" VAR byte displayFunction, cols, rows, backLightVal, displayControl, displayMode long d PUB Main waitcnt(clkfreq * 2 + cnt) debug.startx(pcDebugRX,pcDebugTX,pcDebugBaud) debug.strln(string("Started serial communication...")) debug.putc(13) i2cObject.Initialize(i2cSCLLine) repeat 3 debug.putc(".") waitcnt(clkfreq / 2 + cnt) debug.putc(13) backLightVal := LCD_NOBACKLIGHT waitcnt(clkfreq / 20 + cnt) i2cObject.Start(i2cSCLLine) debug.strln(string("I2C - Started...")) debug.putc(13) i2cObject.Write(i2cSCLLine, LCD_Addr | 0) debug.strln(string("I2C - Address written...")) debug.putc(13) d := backLightVal i2cObject.Write(i2cSCLLine, (d | backLightVal)) debug.strln(string("I2C - Value written...")) debug.putc(13) i2cObject.Stop(i2cSCLLine) debug.strln(string("I2C - Stopped...")) debug.putc(13) waitcnt(clkfreq + cnt)
Here is how I wired the project... I use 4 bi-directional voltage level converter from Adafruit between the Propeller ASC+ and LCD. LCD is powered by 5V and SCL and SDA pins are pulled up using 4.7k at the 3.3v side (which I think will be converted to 5V at the LCD side by the level converted... if not, please let me know)... It is also important to point out that I soldered the smd jumper in the back of the Propeller ASC+ for pin 0 and pin 1 as suggested at http://mghdesigns.com/wiki/asc:start
Why the backlight not turning off? What am I doing wrong? Can anyone help?
Thank you for your time and help,
TheKaduu
Comments
I have two of these and addresses can be changed using jumpers as shown in the image. As the other image shows (not from 20x4 wiki page but from 16x2 wiki page... But the same backpack) that I have it in $20 address (I am using the top one). As far as the Arduino example at the DFRobot wiki page you mentioned, they must have taken all the jumpers of for that to work
Thank you for your time.
TheKaduu
Also, the Propeller already has an I2C buss that you can use which will free up a couple pins. You can in fact share the buss that the boot EEPROM (pins 28 and 29) is connect to.
I was confused by this previously when I was testing the LCDs with Arduino... I will try this and let you know.
JonnyMac:
Another question... The I2C chip (http://www.dfrobot.com/image/data/DFR0154/PCA8574 Datasheet.pdf) on these LCD modules are 2.3v to 5.5v. I am powering using 5v. Do I have to use the voltage level converter at all? In other words, does powering the LCD with 5v make the SCL and SDA 5v level? I just answered my own question... Please check out the page 14 of the documentation about "Input SCL; input/output SDA"...
Thanks anyway... (I am not deleting what I just wrote. It might benefit someone, I hope.)
Thank you for your time.
Yes, but, ultimately, you may want to use a high-speed (PASM) I2C driver and have it shared among devices -- you can't do this if the devices are connected to different pins. Using extra pins is fine if you have them; having started with the BASIC Stamp 1 I'm always in "resource conservation" mode.
Interesting point of view. I always went nuts because lots of data-sheets specify 7 bit addresses and the code required 8 bits. Still other datasheets give it to you as binary with leading zeros removed. Thanks.... that's very helpful. I wouldn't care one way or the other but when I first started coding my own object I thought it made more sense to pass the 7 bit address to the object and let it do the manipulation to create the read/write address from that and lots of the datasheets I was looking at gave 7bit addresses.
I wish they would just pick one way and all do it the same!
Indeed... Thanks again. I will use the PASM I2C on pins 28 and 29 tonight along with << 1.
Thank you for your time.
Edit: Attached image shows that the LCD still functions OK with the Arduino setup...
Thank you for your time...
Thank you.
FWIW, could you verify what the prop thinks is available in the bus? I'll attach Tim Moore's i2cScan object modified for FDS usage.
Hopefully, this is not the EEPROM on the ASC+ board... If so, the LCD is somehow not visable, right?
I unplug the LCD, rerun the scan and still get the same thing. Therefore, the LCD is not being recognized.
What's next?
Thanks Kuroneko.
EDIT: I had to put the output into the code block to get it show up...
Meanwhile, I did the same thing on the Arduino side and got the following:
Now I have a different problem. The DFRobot LCD library is using Stdio.h through Print.h as shown below:
How this could be implemented in SPIN?
Thank you for your time.
TheKaduu
Thanks JonnyMac.
Is there a schematic for the LCD? The data sheet is for the core chip, not for the LCD module. Knowing the connections would make helping you create object for it far easier. Who's to say that the Arduino library you're using now is best?
Thanks.
Hints:
-- the LCD is connected in four bit mode
-- this means there will be six i2c writes per character
* write byte (2 writes) with E low, write byte (2 writes) with E high, write byte (2 writes) with E low again
-- RS bit is decoded as command (0) or character (1)
I also recommend DFRobot. They are relatively cheap and have fast shipping. I get what I ordered in 3-4 days from China (where they are located) for $10-12 shipping (DHL). I am in Florida... You should be able to get it in 1-3 days.
Anyway, I ordered FTDI cable and once it's here, I will fix the Sparkfun Graphic LCD which we have an object for in the OBEX. I already hooked that up and got it to run in as much time as it takes to wire it up and upload the code to the propeller
If it's not going to be too much trouble for you, can you explain the hints you gave? I saw the LCD init function in the DFRobot library was trying to switch to 4 bit mode.... But, why would there be 6 I2C writes? A char is one byte which would take 2 writes in 4 bot mode, right? Where does the extra 4 writes coming from? Also, I did not understand the last hint. Sorry.
Thank you for your time.
write character with E clear (2 writes)
write character with E set (2 writes)
write character with E clear (2 writes)
You can see this in the .cpp code (pulseEnable calls expanderWrite twice):
Do you think I would be ok if I use the "send" to send the characters one by one since I already converted the "write4bits", "expanderwrite" and "pulseEnable" methods to SPIN?
Thanks.
Note that I have my own very simple I2C library (based in part on Mike's code) that has just a few methods: start, write, read, and stop -- I'm basing my example on that.
I did it little bit different but I'll try those... Meanwhile, I did a work around for my problem. I basically send the values to Arduino Mega to use the I2C library from DFRobot to display the values. It is a lot like reaching your left ear with right hand, but it serves the purpose. Here is the code for both and attached images are the setup:
NOTE: Arduino code is pasting fine but SPIN code is not... Admins??
I have the same LCD and would love to look at some code that will talk to iy.
I to can make it work with the Arduino , but having troubles with the prop.
Thanks
JonnyMac: Below pasted code is what I have so far. I am able to INIT the LCD (which comes back with backlight off) and turn on the back light... Beyond that, I haven't been able to write characters or anything else to it. The screen looks like it is just connected to power (attached image).
Any ideas? Can you check the code (espacially the Str subroutine) and give us some feedback?
Thank you for your time.