Show Posts
Pages: 1 [2]
16  Forum 2005-2010 (read only) / Interfacing / Re: n00b SPI problem on: December 27, 2009, 12:27:56 pm
Hi folks,
The posted code works fine except that you want to change the type of return value for the read_register16 from a float to an unsigned long, same as the variable it's acting on. I had some funny business until I changed this.

unsigned long read_register16(char register_name)

Also, if you want to run this on a 5V board, check out this page on Spark Fun for how to do it. I used the resistor method and everything is working fine.

whoops, how about a link?  smiley-wink

http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=65
17  Forum 2005-2010 (read only) / Interfacing / Re: analog in to 4 bit LCD driver on: October 17, 2006, 09:42:51 am
Hey Neill,
I haven't tried your 4 bit library yet. The newer init code I posted above works fine for either a 2 or 4 line display. A quick glance at the excellent links you have on the LCD's processor's internal init functions leads me to believe that it probably isn't necessary to do a hard init of an LCD unless you want it to do a mode other than its native format (ie getting a 2 line display to only do 1 line). I don't have a 1 line display so I can't check that configuration. Thanks for the tip on the integer to string function. One thing I do enjoy about the Arduino is actually having to worry about keeping code lean and mean! Reminds me of the "good" old days with my Timex Sinclair smiley-wink

I could see people either using the "clear screen" or "reset to home" commands depending on what they want to do. "reset to home" sometimes looks nicer because it doesn't have the slight flicker that the "clear screen" function has.

Another interesting thing I found this weekend, after writing a little mac app to talk to the Arduino and set stuff on the LCD (if anyone's interested I'd be happy to post it) is that the serial(USB) port only seems to take in 65 bytes max at any one time? Is this a limitation of the hardware or the serial library?

At this rate, I might not get a chance to mess around with this until the weekend, but I've got plenty of stuff to read and try, thanks to you. Good show.

Dave
18  Forum 2005-2010 (read only) / Interfacing / Re: analog in to 4 bit LCD driver on: October 16, 2006, 10:50:25 pm
Hey Neill,


I'll give your code a look and see if we can't get the best of both of ours together (it might end up being all your's!) smiley-wink
19  Forum 2005-2010 (read only) / Interfacing / Re: analog in to 4 bit LCD driver on: October 16, 2006, 10:48:36 pm
Hey Neill,

I was playing around this weekend, trying to get everything to work well on a cold power up, and the following seems to work every time- works on a 20x4 LCD screen, and should also work on 1 and 2 line screens, although a 16x2 screen starts the second line at the 40th character. a 20x4 display does the first line, then the third, then the second, then the 4th...fyi.

the following does best in the setup function.

 int i;
 for (i=Enable; i <= DI; i++)
   pinMode(i,OUTPUT);

delay(200);

  LcdCommandWrite(2);  // set cursor to home
                        
 delay(200);                      
 LcdCommandWrite(2);  // do it again for good measure
                        
 delay(33);                      
 LcdCommandWrite(14);  // flat cursor, no blinking
 
 delay(50);                    
 
LcdCommandWrite(1);  // erase screen (if desired)
                      
 delay(20);    
20  Forum 2005-2010 (read only) / Interfacing / analog in to 4 bit LCD driver on: October 11, 2006, 12:13:20 pm
Hi all,
I combined and modified some of the tutorials to allow driving an LCD display in 4 bit mode, to save digital pins. The result is a program that can display temperature on an LCD and turn a digital pin on and off, to control a heater or other device. I'd post it in the playground but I haven't figured out how to create a new page.

Enjoy!

Dave

/* Analog in to LCD 4 bits
 * ---------
 * Adapted from the "analog_read_send" and "lcd_8bits" tutorials.
 * This example uses 4 less pins on the Arduino than the 8 bit example.
 * It will take a reading from a 'K' Type thermocouple ice point reference chip
 * on Analog Input 2 and display the temperature in degrees Centigrade on the LCD.
 * One can also set a target temperature for turning a relay off, say for a heater,
 * at a given setpoint temperature. This is done on digital pin 4.
 *
 * These are the pins used on the LCD:
 *
 * - DI(register select), RW, DB4..DB7, Enable (7 in total)
 *
 * the pinout for LCD displays is standard and there is plenty
 * of documentation to be found on the internet.
 *
 * 2006, Dave Sopchak  glasspusher at outofoptions dot net
 *
 */
 
int DI = 12; // register select
int RW = 11;
int DB[] = {7, 8, 9, 10};
int Enable = 6;

int temperaturePin = 2;    // select the input pin for the temperature
int ledPin = 13;           // pin for the LED

void tickleEnable()
{
 // send a pulse to enable
 digitalWrite(Enable,HIGH);
 delayMicroseconds(1);  // pause 1 ms according to datasheet
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);  // pause 1 ms according to datasheet
}

void cmdWriteSet()
{
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);  // pause 1 ms according to datasheet
  digitalWrite(DI,0);
  digitalWrite(RW,0);
}
void LcdCommandWrite(int value)
{
 int i = 0;

  for (i=DB[3]; i >= DB[0]; i--) // high nybble first
  {
    digitalWrite(i, value & 128);
    value <<= 1;
  }
    cmdWriteSet();
    tickleEnable();

  for (i=DB[3]; i >= DB[0]; i--) // low nybble next
  {
    digitalWrite(i, value & 128);
    value <<= 1;
  }
    cmdWriteSet();
    tickleEnable();
}

void LcdDataWrite(int value)
{
 int i = 0;
 
 digitalWrite(DI, HIGH);
 digitalWrite(RW, LOW);
  
  for (i=DB[3]; i >= DB[0]; i--) // high nybble first
  {
    digitalWrite(i, value & 128);
    value <<= 1;
  }
    tickleEnable();

  for (i=DB[3]; i >= DB[0]; i--) // low nybble next
  {
    digitalWrite(i, value & 128);
    value <<= 1;
  }
    tickleEnable();
}

void setup (void)
{
 int i;
 for (i=Enable; i <= DI; i++)
   pinMode(i,OUTPUT);

 delay(100);
 // initiatize lcd after a short pause
 // needed by the LCDs controller
 LcdCommandWrite(0x28);  // function set:
  delay(64);             // 4-bit interface, 2 display lines, 5x7 font
                         // other interaces:
                         // 0x20 = 4 bit, 1 display line

 LcdCommandWrite(0x28);  // function set:
  delay(64);             // 4-bit interface, 2 display lines, 5x7 font
 
  LcdCommandWrite(0x06);  // entry mode set:
                         // increment automatically, no display shift
 delay(20);                      
 LcdCommandWrite(0x0E);  // display control:
                         // turn display on, cursor on, no blinking
 delay(20);                      
 LcdCommandWrite(0x01);  // clear display, set cursor position to zero  
 delay(100);                      
 LcdCommandWrite(0x80);  // display control:
                         // turn display on, cursor on, no blinking
 delay(20);      
}

void loop (void)
{
  int i, val = 0;
  
  for(i = 0; i < 20; ++i)
  {
        val += analogRead(temperaturePin);    // read the value from the sensor
        delay(50);
  }
  
  val /= 4.06;      // conversion value to millivolts
  
  digitalWrite(ledPin, HIGH);  // turn the ledPin on
  delay(500);                  // stop the program for some time
  digitalWrite(ledPin, LOW);   // turn the ledPin off
  
  if(val > 175 * 10)   // temperature in deg C times 10, since we're measuring to tenths of a degree
      digitalWrite(4,LOW);
   else
     digitalWrite(4,HIGH);

    LcdCommandWrite(0x02);  // set cursor position to zero  
  delay(10);                    
  firstDisplay(val);
}

void firstDisplay(int value)
{
  int first,second, third, fourth;
  
  first = value / 1000;    //
  second = (value - 1000 * first)/ 100;
  third = (value - 1000 * first - 100 * second)/ 10;
  fourth = (value - 1000 * first - 100 * second - 10 * third);
 
      LcdDataWrite('T');
      LcdDataWrite('e');
      LcdDataWrite('m');
      LcdDataWrite('p');
      LcdDataWrite(' ');
      LcdDataWrite('=');
      LcdDataWrite(' ');

      LcdDataWrite(value > 999 ? first + 48 :  ' ');  // begin onscreen
      LcdDataWrite(value > 99 ? second + 48 : ' ');
      LcdDataWrite(third + 48);
      LcdDataWrite('.');
      LcdDataWrite(fourth + 48);

      LcdDataWrite(' ');
      LcdDataWrite('C');
      LcdDataWrite(' ');
      LcdDataWrite(' ');
}
Pages: 1 [2]