I2C 1602 LCD display for WC8

START
CALLSUB LCD_INIT
DELAY 4
SET RAM20 0x80 # address first line, first byte
CALLSUB LCD_CMD
SET RAM20 0x4F # data byte ascii code for O
CALLSUB LCD_DATA
SET RAM20 0x4B # data byte ascii code for K
CALLSUB LCD_DATA

TASKS:
SET VAR2 T1
GOTO TASKS
END

LCD_INIT:
DELAY 20
I2CWRITE 1 0 78 #I2C address
I2CWRITE 0 0 0x38 #write 0x3 lit on
I2CWRITE 0 0 0x3C #E bit on
I2CWRITE 0 0 0x38 #write 0x3
DELAY 7
I2CWRITE 0 0 0x38 #write 0x3
I2CWRITE 0 0 0x3C #E bit on
I2CWRITE 0 0 0x38 #write 0x3
DELAY 1
SET RAM20 0x32 # still part of init
CALLSUB LCD_CMD
DELAY 5
SET RAM20 0x28 # 4 bit, 2 line, font size 5x8
CALLSUB LCD_CMD
DELAY 5
SET RAM20 8 #display off
CALLSUB LCD_CMD
DELAY 5
SET RAM20 1 # return home
CALLSUB LCD_CMD
DELAY 5
SET RAM20 6 # entry mode on
CALLSUB LCD_CMD
DELAY 5
SET RAM20 0xF #display on, cursor on, blink on
CALLSUB LCD_CMD
RET

LCD_CMD:
ANDB RAM20 0xF0 RAM21 #upper nibble
ORB RAM21 8 RAM21 #turn on lit
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM21
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
ROTL RAM20 4 RAM21 #move to upper nibble
ANDB RAM21 0xF0 RAM21 #only upper 4 bit
ORB RAM21 8 RAM21 #turn on lit
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM21
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
RET

LCD_DATA:
ANDB RAM20 0xF0 RAM21 #upper nibble
ORB RAM21 9 RAM21 #turn on lit, R/S bit on
I2CWRITE 0 0 RAM21
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
ROTL RAM20 4 RAM21 #move up 4 bits
ANDB RAM21 0xF0 RAM21 #upper nibble
ORB RAM21 9 RAM21 #turn on lit, R/S bit on
I2CWRITE 0 0 RAM21
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
RET



 
 
If continuously writing bytes to the same line, you do not have to set cursor position between write byte
 
@klaatu,
 
This is one example. If you have this I2C device, hook up and test it out the PLC code, then you can understand I2C easily.
 
I do not have this I2C device, not any need for one.  I have a need for an ADC to restore the missing 4 analog inputs that I was counting on having when I bought the board.

I could use more, if the IC2 bus can chain them, like appears to be the case.  That would be a plus.  But I don't know how that affects the ability to ship the extra data out the getall string, or how/where they might be displayed in the staus page
 
klaatu said:
  But I don't know how that affects the ability to ship the extra data out the getall string, or how/where they might be displayed in the staus page
 
Short answer: they don't magically appear.
I know I did ask for AIP5/6/7/8 to be made writable in PLC code, I'm not sure if it happened or not.
If it did, then in your code, where you read an analog channel from the SPI/I2C bus (in your own code), you could then write the value to A5/A6, etc and use it "as if it had been read by the WC8 as a real ADC input"... but I really don't know if it happened or not.
 
If it didn't you'll need to set aside one (or more) VARs that you can see on the status page, and read with getall, and just "know" that VAR1=AIP5, for example.
 
In my own code, I've written a client/server app where the WC8 "calls home" periodically. When it does, the server replies with a code that the WC8 uses to work out what to do next. This could be "send back the current temperature" or "send back the current barometric pressure" etc. The sequence ends with a "Call back in (x) seconds", which lets me synchronise when the different weatherstations call in, and to adjust the update frequency. For example, I read the wind speed and direction from most stations every 10 seconds. Some stations I read every 5 seconds. Some don't have anemometers, and I only request information from them every 5 minutes.
It's slightly more complex than polling a board, but it's quite scalable, and it also overcomes the problem of having boards behind NAT gateways or firewalls, or on IP addresses that change frequently.
 
Thanks Ross

Yes, I found last night that the ai5-ai8 fields were left writable when they pulled the ds2450.  "We also removed 1-wire DS2450 four channel ADC support, but let user settable AIP5-8, so that user can use I2C multiple channels ADC chips out there."  That was said a year ago, presumably/hopefully it's in my firmware that way, I haven't checked yet.  And I realized about that time that I could use the debugging Vars as well.  So there is 12.  I don't need to expect more than that out of one board

I did read your weatherstation post, quite slick but I don't need that level of function, at least not yet that I can see.  I have a working weatherstation, an OS WMR100 with some additional remote sensors, using the WSDL software from sourceforge, and am already using the data from it along with the wc8 sensors to make decisions about local process activities.  Remote weather doesn't concern me, and no other nearby weatherstation comes close to reporting usefully about my ultra-micro climate.  I have a small dedicated pc that collects all the data from both into sqlite.  I can massage those numbers however I wish, and feed some decision bits back to the wc8 to trigger results.  I have my old labjack for that, made good use of it.  I don't need to cross any firewalls, everything is local

Mostly, I have some pretty severe scheduling constraints to begin with, which is why I choose the wc8 over an arduino or rpi, and I just lost another device that was controlling all the drip fertigation, after a nearby lightning strike.  It had allowed me to expand operations beyond anything I had previously been able to do, and now I am operating those zones/valves by hand until I can get the wc32 in its place.  It's a desert environment with a lot of container stock in high drainage soiless media and the system requires a couple dozen activations thruout the day & night, I'm getting a bit weary from it  :)   I hadn't needed to add in the analog moisture sensors just yet, and the various time crunches were keeping the ds2450 on my desk.  Now, it could be quite useful to get them in the rapid deployment channel. I was planning on only three for this webcontrol, but if I can get more it would really help

I did read you saying somewhere that the wc8 is using 10 bits, am I constrained to a 10 bit ADC?  There's no way I am going to be making a pcb, I need something already on a little board that I can at least see as semi-plug and pray, if not better, other than dealing with the code.  There's a 12bit ADS1015 on a pcb, I'm not going to have negative voltages, if I use it single ended the sign bit isn't there, can I somehow drop the least significant bit from the remaining eleven and make it work?  I don't need a lot of precision, and they are cheesy sensors to begin with.  Bone dry, flooded, and somewhere in between would be a good start.   At this point if I could gang three of those onto the wc8 and fill all 12 empty fields that I have to play with, I could breathe a lot easier

The other issue that is waving at me is the cable lengths.  I don't need a kilometer, although reading the Analog sensor long range thread was seriously recreational.  So much can be hidden behind a simple title, like learning about a linesman finding a buried cable with a bad neutral, using only his nards.  Such detail.  My cables to some of the moisture sensors could be maybe a couple hundred feet tho. My imagination is seeing cat5 inside 1/2" steel emt, and I am fine with that as long as the ADC doesn't care
 
@klaatu
DS2450 is more like six bit accuracy from our testing. It requires very careful PCB layout to make it work reliably.  That is probably one reason Dallas discontinued it.  There are many 12bit ADC with I2C interface. AIP5-8 are 16bit variables so that storing 12 bit value is not a problem.  If you like to use this 16 bit ADC/I2C board to implement an I2C ADC expansion, we can purchase it at the same time, so that we can work with you in steps. We would prefer to open a separate topics instead of mixing up with I2C LCD topics.
Code:
http://www.ebay.com/itm/361338787943
 
If you have the I2C LCD module, it shows on each pin a name label. On the rev 2.3.x WC8, it has terminals also marked on its edge. Find the matching name and connect those pins together.  On the rev 2.2.2 WC8 board, please refer to the user guide, which has a picture showing pin names for the I2C and SPI connections.
 
To display information, copy and paste above sample code into PLC window, then you will see what display on the LCD. Play with the location and content to display will help you familiar with how to display the information you wanted.
 
Hello,
The display linked in the first post no longer displays on ebay. Is this one suitable
EBay item number
301553014205

(Sorry, can't post links yet since I've not posted enough messages)

Thanks
 
Sure, that should work. The I2C chip module piggyback on the LCD module seems identical to the other one, that is the most important part.
 
I received my display and have it working great. Thanks for the sample code.
 
Just a note for anyone who thinks the display/code is not working and their screen is just blank.....check the contrast adjustment on the back!
 
I spent a little while messing about with different addresses/supplies/etc until I realised the reason my display was totally blank was due to the fact the display arrived with the contrast set to one end of the scale!
 
Back
Top