Show Posts
Pages: 1 ... 29 30 [31] 32 33 ... 44
451  Using Arduino / Networking, Protocols, and Devices / Re: I2C LCD -- changing startup screen problem on: April 20, 2011, 01:25:08 pm
Matrix Orbital recommended a delay between every char, so I tried this, but it still only gives the first 2 characters.
He thinks, like myself, that it just some little issue in the transmission that needs tweeked.

Code:
#include <Wire.h>
void setup(){
Serial.begin(9600);
  Wire.begin(); // join i2c bus (address optional for master)
  //TWBR = 250;
delay(4000);  //gives a chance to connect to serial before it starts
  Wire.beginTransmission(40);
Wire.send(254);  //(0xFE); init commands
        delay(50);
Wire.send(64);  //(0x40); init. startup
        //send 32 characters with a 50ms delay
        for(int i = 56; i <= 87; ++i){
          delay(50);  //I've tried: 50, 30, 20, 60,90,120,180
          Wire.send(i);
        }
        int w = Wire.endTransmission();
        Serial.println(w);
}

void loop(){
}
452  Using Arduino / Networking, Protocols, and Devices / Re: I2C LCD -- changing startup screen problem on: April 19, 2011, 11:13:49 pm
I'm still here.  I tried this code, and it Serial.prints 4.  Unfortunately, it only loads the first 2 characters.  I tried different vals for the buffers, but I still only get 2 chars, now.  Furthermore, I tested the sketch on my 2nd new LK1602 -12, and now I've got 2 units with bad splash screens.  This one doesn't have vertical bars for the other 30 spaces, it's got some chinese character or such.  (The same one for each char.)
I also tried using the line
Code:
TWBR = 250;
--I tried: 50, 100, 200, & 250.  It didn't seem to change anything
Code:
#include <Wire.h>
void setup(){
Serial.begin(9600);
  Wire.begin(); // join i2c bus (address optional for master)
  //TWBR = 100;
  delay(3000); 

 
  Wire.beginTransmission(40);
Wire.send(0xFE);
Wire.send(0x40);
Wire.send("3234567890123 167890123 26789 32");
int xyz = Wire.endTransmission();
Serial.println(xyz);
}

void loop(){
}
I've got good jumper wires going to my display.  It's just strange, all the other features are working.  I'm going to try uninstalling arduino & libraries, and reinstalling...
453  Using Arduino / Sensors / I give up on debouncing light on: April 19, 2011, 10:49:24 pm
I just can't quite get my brain around this photocell debouncer.  All I need is a boolean that is true if it's light, and false if it's dark.  Light and dark being set by MySettings.Photocell_Level.  I don't want the boolean to oscillate when the light level is close to the threshold, though, so I thought I'd add a 5 second debouncer to it.  I've struggled too long on this one...
This is a mess, but:
Code:
void Photocell(){
  boolean newLightLevel;
  boolean prevLightLevel;
  long lightDebounceTime;
  int senseVal = analogRead(photocellPin);  //get the pin reading
  Serial.print("photocell reading: ");
  Serial.println(senseVal);
  if (senseVal > 62)  newLightLevel = true;  //light level is higher than threshold  MySettings.Photocell_Level
  else  newLightLevel = false;  //it's darker than threshold

  if (newLightLevel != prevLightLevel) {    // lighting has changed
    lightDebounceTime  = millis();    // reset the debouncing timer
    prevLightLevel = newLightLevel; //the previous light is now the current reading
  }
    if (millis() - lightDebounceTime > 5000) { //It's stayed either light or dark for 5 seconds
      Serial.print("Level changed to :");
      lightLevel = newLightLevel;  //True for light, False for dark
    }     
      if(lightLevel) Serial.println("LIGHT");
      else Serial.println("DARK");

}

By all means, if there's a better way to go about this, please do tell!
454  Using Arduino / Networking, Protocols, and Devices / Re: Strange behaviour of I2C LCD w/keypad on: April 19, 2011, 02:30:51 pm
This time based refresh still didn't work:  About 1 out of 6-8 keypresses would be missed.  I got to looking, I found if I took out the setCursor line, it worked, even though it was still writing the Sensor val line.
So I looked in the library at the setCurosr and found this:
Code:
void LCDI2C::setCursor(int line_num, int x){

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x47);
Wire.send(line_num);
Wire.send(x);
Wire.endTransmission();
delay(100);
}
...I commented out the delay(100), and now it works fine!  I don't know if/why that's there, but unless  I find trouble somewhere else I'll just leave it commented out.
455  Using Arduino / Networking, Protocols, and Devices / Re: Strange behaviour of I2C LCD w/keypad on: April 19, 2011, 01:02:58 pm

The print commands are interfering with the keypad so you must print as little as possible.

try this; it is definitely not 100% robust but as it will only print the FlowSensorCount if it is changed it can spend far more time reading the keypad()

Code:
int prevCount = -1;  // assuming FlowSensorCount cannot be negative

do
{
  if (prevCount  != FlowSensorCount)
  {
    prevCount  = FlowSensorCount;
    lcd.setCursor(13,2); 
    lcd.print(FlowSensorCount);
  }
  getkey  = lcd.keypad();
  if (getkey != 0) break;
} while(1);
Thanks, I'll try this out.  FLowSensorCount changes at a max rate of 16 pulses per second, so do you think this should be pretty dependable with the keypad response, then?
 
456  Using Arduino / Networking, Protocols, and Devices / Re: I2C LCD -- changing startup screen problem on: April 19, 2011, 12:06:38 pm
I may be gone for a few days, but don't go away! 
I have 2 of these MatrixOrbital displays, I could try the other one.  I don't think it's the display because most things are working fine.  (I hate to mess up the default splash on the 2nd one, if I can't get something but vertical bars)
I'm going to try all new wiring, new resistors (4.7K), fiddling with TWBR, a new USB cable, and a different AC outlet for my wall wart! smiley-roll
457  Using Arduino / Networking, Protocols, and Devices / Strange behaviour of I2C LCD w/keypad on: April 19, 2011, 12:02:17 pm
I'm slowly solving some little quirks about this Matrix Orbital LCD/Keypad controller
This code works great, it never misses a keypress:
Code:
do{
   getkey  = lcd.keypad();
   if (getkey != 0) break;   
 //  lcd.setCursor(13,2);  //COL, ROW
 //  lcd.print(FlowSensorCount);
 }while(1);
...but with this code, I have to sometimes press a key 3 or 4 times to get any response.
Code:
do{
   getkey  = lcd.keypad();
   if (getkey != 0) break;   
   lcd.setCursor(13,2);  //COL, ROW
   lcd.print(FlowSensorCount);
 }while(1);
Both codes are just waiting for user input on any key.  It'd be nice to show a little feedback on the screen while I wait, but it's a major problem if they have to push a key 3 times to get it to respond.
458  Using Arduino / Networking, Protocols, and Devices / Re: I2C LCD -- changing startup screen problem on: April 19, 2011, 01:31:05 am
I got a 4 on the NAK scale... Is that a good grade?  What's it mean in layman's terms? 

Look at what I posted above. 0 is good, any other number isn't.

4 sounds particularly bad, like there is electrical trouble. The 2.7K resistors sound a bit high to me, try 4.7K.
Yes, I gathered 4 was bad, I just didn't know 'how bad'  it's greek to me.
This will be great if it's just the resisters!  I searched that out and found some folk same 4.7, some 1.5.  I hope that's the problem!
g'night.
459  Using Arduino / Networking, Protocols, and Devices / Re: I2C LCD -- changing startup screen problem on: April 19, 2011, 01:08:06 am
I have 2.7K resistors on A4 and A5 to +5 volts.  I'll double check, that their connected good, but their soldered on my custom pcboard, so they should be.  
Now, I can't get the splash screen to take anything but the first 2 characters, again!!!  No matter what I do, only the first 2 characters stick!

I've found 1 other bug too:
the remember feature on the LCD
Quote
lcd.command2(147,1);  //turn remember on
lcd.command2(147,0);  //turn remember off
I've tested this by inserting the block cursor on or off in between these lines, and the LCD remembers the setting each time it's powered up.  Buy I've never gotten it to remember to keep the backlight on indefintely with the command:
Code:
lcd.command2(66,0);       //turn on backlight for ever
Quote
254 66 [minutes]  Backlight will stay on for [minutes]. If [minutes]= 0 backlight will stay on permanently.

I got a 4 on the NAK scale... Is that a good grade?  What's it mean in layman's terms?  Bad wiring?  My wiring seems good.  I made the harness myself!  (Ha, I know what you're thinking...)
Tomorrow I'll triple check my resistors, and use different wires, I'll just use 6 inch jumper wires.  I twisted my sda/scl/ground/5 volt wiring all together, --it's only 6 inches long, so that should be a problem...
I'm about ready to got back to the dreaded 7 wire plain old LCD!

460  Using Arduino / Networking, Protocols, and Devices / Re: I2C LCD -- changing startup screen problem on: April 19, 2011, 12:33:26 am
ps.  This sending a splash screen locks things up.  Like -- this should loop, but it only prints 4 once.  I have to power down the LCD to do anything more.
461  Using Arduino / Networking, Protocols, and Devices / Re: I2C LCD -- changing startup screen problem on: April 19, 2011, 12:31:42 am
I made these both 34:
Code:
#define BUFFER_LENGTH 34
in wire.h
Code:
#define TWI_BUFFER_LENGTH 34
in twi.h

this code prints '4' to the serial monitor, and only it's back to putting only 2 characters of splash on the LCD again:
Code:
#include <Wire.h>
void setup(){
Serial.begin(9600);
  Wire.begin(); // join i2c bus (address optional for master)
}

void loop(){
  delay(3000); 
  Wire.beginTransmission(40);
Wire.send(254); //0xFE);
Wire.send(64); //0x40);
Wire.send("12345678901234567890123456789032");
int xyz = Wire.endTransmission();
Serial.println(xyz);
}


The above is without the library, just modified 32 to 34 on those 2 buffers.
462  Using Arduino / Networking, Protocols, and Devices / Re: I2C LCD -- changing startup screen problem on: April 18, 2011, 10:41:38 pm
Okay, I've uploaded about 75 test sketches, and here's some stuff I've come up with.  First, I had the same results using either of these in the LCDI2C library:
Code:
void LCDI2C::writeStartUpScreen(char * message) {
Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x40);
Wire.send(message);
Wire.endTransmission();
delay(CMDDELAY);
}
Code:
// Write Start-Up Screen
void LCDI2C::writeStartUpScreen(char message[]) {
Wire.beginTransmission(g_i2caddress);
Wire.send(254); //0xFE);
Wire.send(64); //0x40);
Wire.send(message);
Wire.endTransmission();
delay(CMDDELAY);
}
I use something like this (only I changed it slightly each time, so I could tell if it was doing anything:
Code:
lcd.writeStartUpScreen("12345678901234567890123456789012");
I changed
Code:
#define BUFFER_LENGTH 32
to
Code:
#define BUFFER_LENGTH 34
It will upload the first 20 characters*.  smiley
I changed the buffer length to 40, and it would still only upload the first 20 characters*. smiley-confuse
I searched about the wire library, found reference to twowire.  So in libraries/wire/utility/twi.h, I changed
Code:
  #define TWI_BUFFER_LENGTH 32
to 60:
And now it loads 26 characters*!  smiley-lol
There must be some other buffer somewhere that's holding things up, maybe?  Any thoughts?

*by this I mean the rest of the screen is filled with vertical bars.
463  Using Arduino / Networking, Protocols, and Devices / Re: I2C LCD -- changing startup screen problem on: April 18, 2011, 11:19:11 am
This new code compiles, but it still only loads the first 2 characters to the splash screen.  I tried sending a 32 character length text like:
Code:
lcd.writeStartUpScreen("Greetings folks! here is the rst");
but it only gets the 'Gr' and the rest of the display is vertical bars.
I just heard back form MatrixOrbital, they said:
Quote
I understand it appears that the start screen of your LK162-12 is not being changed correctly by your Arduino controller.  If the display is having trouble receiving any characters it will NAK the data line, I believe the Arduino endTransmission function will indicate this.

As for the command, you might try padding the string with spaces to make it 32 characters long, the size of the screen. 

So I've tried the padding, but 'NAK'???  --does it send some kind of signal back that I can check to see if it's not getting the message?  I feel pretty sure it's something in the transmission/timing, but I don't know what.  Any other suggestions?
464  Using Arduino / Networking, Protocols, and Devices / Re: I2C LCD -- changing startup screen problem on: April 17, 2011, 07:08:20 pm
What happens if you change
Code:
Wire.send(message);
to
Code:
Wire.send(message, strlen(message));
?
...it doesn't compile, it gives me this error:
Quote
C:\Documents and Settings\x\Desktop\arduino-0022\libraries\LCDI2C_LK162\LCDI2C_LK162-12.cpp: In member function 'void LCDI2C::writeStartUpScreen(char*)':
C:\Documents and Settings\x\Desktop\arduino-0022\libraries\LCDI2C_LK162\LCDI2C_LK162-12.cpp:111: error: invalid conversion from 'char*' to 'uint8_t*'
C:\Documents and Settings\x\Desktop\arduino-0022\libraries\LCDI2C_LK162\LCDI2C_LK162-12.cpp:111: error:   initializing argument 1 of 'void TwoWire::send(uint8_t*, uint8_t)'

I'm using this line in my sketch:
Code:
lcd.writeStartUpScreen("Hello");

And this is the the CPP file from the library:
Code:
/*
 
 LCDI2C v0.4 3/Mar/2009 dale@wentztech.com  http://wentztech.com/Radio
 PORTED FOR Matrix Orbital LK162-12 display 10/Sept/2010 by Brian Brumfield, brian@thebrumfields.com
 
 What is this?
 
 An arduino library for use with the web4robot.com i2C LCD Display in I2C more
 
 Uses I2c Wires interface
 
 Uses Analog pin 4 - SDA
 Uses Analog pin 5 - SCL
 
 
 Usage:
 
 see the examples folder of this library distribution.
 
 
 */


#include <Wire.h>


#include <string.h> //needed for strlen()

#include <inttypes.h>

#include "WConstants.h"  //all things wiring / arduino

#include "LCDI2C_LK162-12.h"


#define LCDI2C_MAX_STRLEN 40
#define LCDI2C_PRINT_STR_DELAY 20


//--------------------------------------------------------

// (don't change here - specify on calling constructor)

//how many lines has the LCD?

int g_num_lines = 2;

int g_num_col = 16;

// Defalt address of the display

int g_i2caddress = 0x50;

int g_display = 0;


//stuff the library user might call---------------------------------

//constructor.  num_lines must be 1, 2, 3, or 4 currently.

LCDI2C::LCDI2C (int num_lines,int num_col,int i2c_address,int display){

g_num_lines = num_lines;
g_num_col = num_col;
g_i2caddress = i2c_address >>1; // ** 7 bit address
g_display = display;

if (g_num_lines < 1 || g_num_lines > 4){

g_num_lines = 2;

}

if (g_num_col < 1 || g_num_col > 40){

g_num_col = 16;
}

}

// Send a command to the display that is not supported

void LCDI2C::command(int value) {

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(value);
Wire.endTransmission();
delay(CMDDELAY);
}

//     I added this:
// Send 2 commands to the display that is not supported
void LCDI2C::command2(int val1, int val2) {

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(val1);
Wire.send(val2);
Wire.endTransmission();
delay(CMDDELAY);
}



// Write Start-Up Screen

void LCDI2C::writeStartUpScreen(char message[32]) {
Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x40);
Wire.send(message, strlen(message));
// Wire.send(message);
Wire.endTransmission();
delay(CMDDELAY);
}


//Used by the print library to get information to the display

void LCDI2C::write(uint8_t value) {
Wire.beginTransmission(g_i2caddress);
Wire.send(value);
Wire.endTransmission();
delay(5);
}




//send the clear screen command to the LCD

void LCDI2C::clear(){

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x58);
Wire.endTransmission();
delay(CMDDELAY);  


}

//send the Home Cursor command to the LCD      ********** Not Working ***************

void LCDI2C::home(){

setCursor(0,0); // The command to home the cursor does not work on the version of the dislay I have
// So we do it this way.
}


//Turn the LCD ON

void LCDI2C::on(int value){

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x42);
Wire.send(value);
Wire.endTransmission();
delay(CMDDELAY);  
}


// Turn the LCD OFF

void LCDI2C::off(){

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x46);
Wire.endTransmission();
delay(CMDDELAY);

}


//Turn the Underline Cursor ON

void LCDI2C::cursor_on(){

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x4A);
Wire.endTransmission();
delay(CMDDELAY);

}


//Turn the Underline  Cursor OFF

void LCDI2C::cursor_off(){

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x4B);
Wire.endTransmission();
delay(CMDDELAY);

}


//Turn the Underline Cursor ON

void LCDI2C::blink_on(){

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x53);
Wire.endTransmission();
delay(CMDDELAY);

}


//Turn the Underline  Cursor OFF

void LCDI2C::blink_off(){

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x54);
Wire.endTransmission();
delay(CMDDELAY);

}


//Move the cursor left 1 space

void LCDI2C::left(){

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x43);
Wire.endTransmission();
delay(CMDDELAY);

}


//Move the cursor right 1 space

void LCDI2C::right(){

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x4D);
Wire.endTransmission();
delay(CMDDELAY);

}


// initiatize lcd after a short pause

//while there are hard-coded details here of lines, cursor and blink settings, you can override these original settings after calling .init()

void LCDI2C::init () {
delay(1000);
Wire.begin();
on(5);
clear();
blink_off();
cursor_off();
home();
}

void LCDI2C::setCursor(int line_num, int x){

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x47);
Wire.send(line_num);
Wire.send(x);
Wire.endTransmission();
delay(100);

}

int LCDI2C::keypad (){

int data = 0;

//  Send Keypad read command
Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x26);
Wire.endTransmission();
delay(CMDDELAY);

//  Connect to device and request byte
Wire.beginTransmission(g_i2caddress);
Wire.requestFrom(g_i2caddress, 1);

if (Wire.available()) {
data = Wire.receive();
}


return data;
}

unsigned char LCDI2C::init_bargraph(unsigned char graphtype)
{
switch (graphtype)
{
case LCDI2C_THICK_VERTICAL_BAR_GRAPH:
Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x76);
Wire.endTransmission();
break;
case LCDI2C_THIN_VERTICAL_BAR_GRAPH:
Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x73);
Wire.endTransmission();
break;
case LCDI2C_HORIZONTAL_BAR_GRAPH:
Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x68);
Wire.endTransmission();
break;
case LCDI2C_HORIZONTAL_LINE_GRAPH:
Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x16);
Wire.send(0x01);
Wire.endTransmission();
break;
default:
return 1;
}

return 0;
}

void LCDI2C::draw_horizontal_graph(unsigned char column, unsigned char row, unsigned char direction,  unsigned char len)
{
Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x7C);
Wire.send(column);
Wire.send(row);
Wire.send(direction);
Wire.send(len);
Wire.endTransmission();
}

void LCDI2C::draw_vertical_graph(unsigned char column, unsigned char len)
{
Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x3D);
Wire.send(column);
Wire.send(len);
Wire.endTransmission();
}

void LCDI2C::load_custom_character(unsigned char char_num, unsigned char *rows)
{
unsigned char i;

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x4E);
Wire.send(char_num);
for (i = 0; i < LCDI2C_CUSTOM_CHAR_SIZE; i++)
Wire.send(rows[i]);
Wire.endTransmission();
}

unsigned char LCDI2C::set_backlight_brightness(unsigned char new_val)
{
if ((new_val < LCDI2C_MIN_BRIGHTNESS)
|| (new_val > LCDI2C_MAX_BRIGHTNESS))
return LCDI2C_VALUE_OUT_OF_RANGE;

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x99);
Wire.send(new_val);
Wire.endTransmission();
return 0;
}


unsigned char LCDI2C::set_contrast(unsigned char new_val)
{
if ((new_val < LCDI2C_MIN_CONTRAST)
|| (new_val > LCDI2C_MAX_CONTRAST))
return LCDI2C_VALUE_OUT_OF_RANGE;

Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x50);
Wire.send(new_val);
Wire.endTransmission();
return 0;
}

// Overload
void  LCDI2C::printstr(const char c[])
{
byte len;

while (*c)
{
len = min(strlen(c), LCDI2C_MAX_STRLEN);
Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x15);
Wire.send(len);
while (len--)
Wire.send(*c++);
Wire.endTransmission();
if (*c)
delay(LCDI2C_PRINT_STR_DELAY); // More to send.  Wait a bit
}
}

465  Using Arduino / Networking, Protocols, and Devices / I2C LCD -- changing startup screen problem on: April 16, 2011, 09:29:55 pm
My I2C LCD display by matrixorbital is all working except for 1 thing:  The command to change the start up screen only sends the first 2 letters to the display, and makes the rest of the startup screen a bunch of vertical bars.
This is the line that sets the startupscreen:
Code:
lcd.writeStartUpScreen("Welcome");
But this will make the startup screen look like this:
We|||||||||||||||||||||
||||||||||||||||||||||||

It's supposed to handle up to 32 chars. (16 x 2 display)
I can change the "Welcome" to any else, and it will only change the 'We' on the splash screen, and leave the bars.


here's a snipet from the library that doing the work:
Code:
// Write Start-Up Screen

void LCDI2C::writeStartUpScreen(char message[32]) {
Wire.beginTransmission(g_i2caddress);
Wire.send(0xFE);
Wire.send(0x40);
Wire.send(message);
Wire.endTransmission();
delay(CMDDELAY);
}

I've sent about a dozen other commands to the LCD, and they all work.
Here's the manual:  http://www.matrixorbital.ca/manuals/LK_series/LK162-12/LK162-12_Legacy/LK162-12_220.pdf
I've about given up!  But I'd like to get rid of the vertical bars...
I've got 2.6K pull-ups on the SDA & SCL.
This is my 1st experience with I2C.
Hope there's a simple solution to this, I've tried everything.
Pages: 1 ... 29 30 [31] 32 33 ... 44