Show Posts
Pages: 1 ... 29 30 [31] 32 33 ... 44
451  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?
 
452  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
453  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.
454  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.
455  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!

456  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.
457  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.
458  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.
459  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?
460  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
}
}

461  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.
462  Using Arduino / Networking, Protocols, and Devices / Changing default settings with my new MatrixOrbital LCD on: April 15, 2011, 01:44:12 pm
I have gotten my I2C LCD to work if I temporarily short the reset pins.  My test sketch does things like print "hello world", it turns the backlight on/off, shows seconds counting...  It all works.  But when I power down the display and then power it up again, nothing works.  But, shorting pins 3 & 4 when I first power it up, makes it work.
I understand that this manual override changes the baudrate, & I2C address.  Evidently one of them is not correct.
The manual for my LCD:
http://www.matrixorbital.ca/manuals/LK_series/LK162-12/LK162-12_Legacy/LK162-12_220.pdf

It says,
Quote
Manual override should only be required in one instance. If for some reason the module is set at a baud rate
which cannot be produced by the host system and all communication to the display is lost, then the user
should follow this simple procedure:
1. Turn off the display
2. Put a jumper on pins 3 and 4 of the keypad connector (R3 and C1).
3. Power up the display. The baud rate is now set to 19,200.
4. Remove the jumper and change the RS-232 port settings to the desired baud rate.
5. Turn off the display.
6. Power up the display.
Refer to the “Set RS-232 Port Speed” command (section 6.1.14) for acceptable baud rates.



So I look at section 6.1.14:
Quote
6.1.14 Set RS232 port speed (254 57 [speed])
This command sets the  RS232 port to the specified [speed]. The change takes place immediately. [speed] is
a single byte specifying the desired port speed. Valid speeds are shown in the table below. The speed can
be manually reset to 19,200 baud in the event of an error during transmission (including transmitting a value
not listed below) by setting the "manual override" jumper on the module during power. This command is
ignored until this jumper is removed again.
Speed Value Speed
FF Hex 1200 baud
81 Hex 2400 baud
20 Hex 9600 baud
0F Hex 19200 baud

...but how do I do that?  I'm using a library, so I don't really know how to do this manual sending of commands.

Here's the library:
http://arduino.cc/playground/Code/LCDi2c
...the link on that page is broke: the library for the LK162-12 is here:
https://public.me.com/digid

In the documentation it says you can do unsupported commands with this:
Code:
command(command) Write a command not supported yet in the library to the display

I can't figure out how to do this...

Extra info: My test sketch that works when I short pins 3 & 4 for manual override
Code:
#include <Wire.h>
#include <LCDI2C_LK162-12.h>
LCDI2C lcd = LCDI2C(16,2,0x50,0);             

void setup(){
lcd.init();
delay(10);
lcd.clear();
lcd.set_contrast(255);
}

void loop(){
  lcd.clear();
  lcd.print(" WELCOME FOLKS!");
  delay(2000);
  lcd.clear();
  lcd.print(millis()/1000);
  lcd.print(" seconds now...");
  delay(1500);
}
463  Using Arduino / Motors, Mechanics, and Power / Re: Pull down resistors keep motors disabled during power-up on: April 12, 2011, 11:52:53 pm
Yes.  When the Arduino starts up the pins are inputs (apart from TX and pin 13) which means they will float.  A pull down of 10k will be fine.

When the pins are output they can source 20 to 30mA if necessary to overcome any pull-downs so 10k is neither here or there.

However the internal pull-up resistors on the Arduino are between 20k and 50k I think.  Best to have your pull-downs an order of magnitude smaller than that, namely 2k2, to ensure they always 'win' should the pins be configured as inputs with internal pull-ups.  That's still only 2.3mA load.

...thanks, that helped me understand what's happening a little better.
464  Using Arduino / Motors, Mechanics, and Power / Pull down resistors keep motors disabled during power-up on: April 12, 2011, 01:08:44 am
Code:
Pull down resistors keep motors disabled during power-up
I see the Adafruit motor shield says this.  Can I add 10K resistors  to my SN754410 on pins 2 & 7 that connect to my Arduino and keep the motor from turning on at startup?
If my 2 motor control pins are 10 and 11, then I'd just add in two 10k resistors from 10 & 11 to ground? That won't interfere with the normal motor operation?
thanks
465  Using Arduino / Motors, Mechanics, and Power / Re: Anyone familiar with the SN754410 on: April 11, 2011, 10:08:56 pm
hmmm.  That's not the answer I hoped for!  smiley-roll
I reckon I'll work in some extras...
Pages: 1 ... 29 30 [31] 32 33 ... 44