How to Use a Screen to Display CPU Temp (not thermistor)?

// include the library code:
#include <LiquidCrystal.h>
#include <Wire.h>
 
#define REDLITE 12
#define GREENLITE 11
#define BLUELITE 10
 
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 3, 4, 5, 6, 7);
 
// you can change the overall brightness by range 0 -> 255
int brightness = 255;
 
void setup() {
  // set up the LCD's number of rows and columns: 
  lcd.begin(20, 4);
  // Print a message to the LCD.
  lcd.print("RGB 16x2 Display  ");
  lcd.setCursor(0,1);
  lcd.print(" Multicolor LCD ");
  
  pinMode(REDLITE, OUTPUT);
  pinMode(GREENLITE, OUTPUT);
  pinMode(BLUELITE, OUTPUT);

  brightness = 100;
}
 
 
void loop() {
  for (int i = 0; i < 255; i++) {
    setBacklight(i, 0, 255-i);
    delay(5);
  }
  for (int i = 0; i < 255; i++) {
    setBacklight(255-i, i, 0);
    delay(5);
  }
  for (int i = 0; i < 255; i++) {
    setBacklight(0, 255-i, i);
    delay(5);
  }
}
 
 
 
void setBacklight(uint8_t r, uint8_t g, uint8_t b) {
  // normalize the red LED - its brighter than the rest!
  r = map(r, 0, 255, 0, 100);
  g = map(g, 0, 255, 0, 150);
 
  r = map(r, 0, 255, 0, brightness);
  g = map(g, 0, 255, 0, brightness);
  b = map(b, 0, 255, 0, brightness);
 
  // common anode so invert!
  r = map(r, 0, 255, 255, 0);
  g = map(g, 0, 255, 255, 0);
  b = map(b, 0, 255, 255, 0);
  Serial.print("R = "); Serial.print(r, DEC);
  Serial.print(" G = "); Serial.print(g, DEC);
  Serial.print(" B = "); Serial.println(b, DEC);
  analogWrite(REDLITE, r);
  analogWrite(GREENLITE, g);
  analogWrite(BLUELITE, b);
}

edit, nevermind must be the code or the upload version i used, i got it to work using different codes and stuff. odd.

Okay, hey guys, I’m not dead, just lots of other crazy stuff going on:

http://i.imgur.com/WFTtEsUl.jpg

So I’ve begun installing everything, and having issues. Forgive me if I leave out details and such, man this is going back a bit. This is a diagram of what’s going on:

http://i.imgur.com/w7tWkxUl.png

So I’m using IDE 1.5.02, I recall we had some hiccups with the IDE’s and not sure what I’m supposed to be using… anyways, Micro selected, COM1 selected. I try to upload anything, even a simple example blink sketch, it just hangs on the uploading. If I tell it to compile again, it’ll say com1 is in use. I gotta restart the program… but yea can’t upload anything to it. Need to do a bit of troubleshooting, like just plugging the usb into a usb header…

The LCD, it shimmers. Or blinks. Every second, it sort of pulses. I’m guessing it has something to do with backlight being hooked up to PSU 5v.

argh the damn arduino is so stuck up in everything it’d be a major pain in the butt to unhook the usb connector as is on it, and swap it. i have no idea what connections are even hooked up or not here, ahh going crazy here. this system is literally getting more complex than the damn computer itself.

but it looks cool, so worst case scenario it’s an awesome looking paperweight.

oh man dont you have to hit a button on the arduino when compiling or something? fuck i have no idea what i am doing anymore. i hit the button over and over and it’s not working.

I’ll have to refresh my memory of how the LCD is wired to the “Arduino” but meanwhile … when these things happen the 1’st rule it to simplify, simplify, simplify. Disconnect the servo and LCD if you can … or remove their power. Then see if you can switch the Arduino power in-sync with the USB connection. I’ve had my Micro (also a 32U4 MCU) hang up and sometimes the reset doesn’t fix it. I get the same COM portX message. It seems that the only way I can get the PC<->Arduino connection back is to unplug the USB cable (which, in my case, also powers the Arduino), wait some seconds and then plug it back in. For me, that’s power and USB at the same time. For you maybe it’s enough to just remove Arduino power, wait and reapply it.

yea i look at devices and there’s no arduino, only unknown device. and i think you’re supposed to get a prompt about plugging in an arduino every time normally. why is it not being recognized hm… plugging off the power wasn’t really doing anything, i unplugged the lcd and servo for the time being too.

okay so yea i plug in a normal usb line and it works. i must have wired the usb header wrong or something, i dunno…

Okay I think I’m going to just use the adafruit trinket + servo + switch + Battery (w/inline spst to shut off for storage), and then use the micro + lcd + volmtetering. So i need to cut the code in 2 now… i think i can do this myself, just saying. I could also go the powered usb hub but i mean that would mean buying extra stuff, it’s not really cheaper than just using a trinket that i already have. it is tempting but it’s not promised that it works and damn this has taken way too long.

code for lcd + micro just run plainly off usb:

#include <LiquidCrystal.h>

//declare the constants to be used
#define LEDPIN 13             //pin attached to LED
#define servoPIN 9            //Servo control line
#define SWitchPIN 2           //input from N.O. momentary switch
#define redPIN 10             //PWM pin for red LED backlight
#define greenPIN 11           //PWM pin for green LED backlight
#define bluePIN 12            //PWM pin for blue LED backlight
#define rsPIN 8               //reset pin for LCD
#define enablePIN 3           //enable pin for LCD
#define d4PIN 4               //data pin4 for LCD
#define d5PIN 5               //data pin5 for LCD
#define d6PIN 6               //data pin6 for LCD
#define d7PIN 7               //data pin7 for LCD
// these constants won't change.  But you can change the size of
// your LCD using them:
const int numRows = 4;
const int numCols = 20;
const int ignoreMAX = 6;      //ignore this many characters
const unsigned long wait = 50;//wait time for ADC update after last Smartie cmd
#define posOpenCMD 1900       //Define Clockwise Servo position in usec
#define posCloseCMD 600       //Define CounterClockwise Servo position in usec
#define DBdelay 2000          //Min time needed btw any 2 button presses, in msec
#define fastSPD 100           //speed setting; 1 = slowest, 255 is fastest (???)
#define slowSPD 15            //Speed Servo/Door opens and closes (15 is good average)
#define DIV_1    1.0          //gain correction for A0 channel
#define DIV_2    1.0          //note it's 1.0, not 1, to get full floating point accuracy

#define V_REF    2.61         //use the measured Aref voltage

//declare the variables used
boolean updateFlag = false;          //flag to refresh ADC readings
volatile boolean doorOPEN = false;   //desired door state set to closed
byte rxbyte = 0;                     //rxbyte is the received byte from Smartie
byte temp = 0;
int ignoreCNT = 0;                   //count of characters to ignore
int row = 0;                         //index of last row position
int col = 0;                         //index of last col position
int rowA0 = 0;                       //index of A0 row position
int colA0 = 0;                       //index of A0 col position
int rowA1 = 0;                       //index of A1 row position
int colA1 = 0;                       //index of A1 col position
unsigned long MSGtime = 0;           //holds the time of the last cursor cmd
volatile unsigned long SWtime = 0;   //holds the time of the last valid switch push
float voltage1 = 0.0;                // calculated voltage for A0
float voltage2 = 0.0;                // calculated voltage for A1

LiquidCrystal lcd(rsPIN, enablePIN, d4PIN, d5PIN, d6PIN, d7PIN);


void setup() {
  //set the pins to be ins or outs
  pinMode(LEDPIN, OUTPUT);
  digitalWrite(LEDPIN, LOW);            //turn LED off
  pinMode(servoPIN, OUTPUT);
  pinMode(SWitchPIN, INPUT_PULLUP);
  pinMode(redPIN, OUTPUT);
  pinMode(greenPIN, OUTPUT);
  pinMode(bluePIN, OUTPUT);


  Serial.begin(9600);

  lcd.begin(numCols, numRows);
  delay(50);
  lcd.clear();
  delay(5);

  analogWrite(bluePIN,0);                //Blue brightness 255-0
  analogWrite(redPIN,255);               //Red brightness 255-0
  analogWrite(greenPIN,255);             //Green brightness 255-0

  analogReference(INTERNAL);              //use the internal 2.56v ADC reference

  //put a hello world on the LCD
  lcd.print("Line 1");
  lcd.setCursor(3, 1);
  lcd.print("Line 2");
  lcd.setCursor(8, 2);
  lcd.print("Line 3");
  lcd.setCursor(13, 3);
  lcd.print("Line 4");
  delay(2000);
}

//this function is used by the smartie code to get data from the PC
byte serial_getch(){
  int incoming;
  while (Serial.available()==0){
    //check to see if enough time has passed since last message from PC
    if((millis() - MSGtime > wait) && (updateFlag == true)){
      updateADC();
    }
  }
  // read the incoming byte:
  incoming = Serial.read();
  return (byte) (incoming &0xff);
}

//this function will update the ADC readings if the [ or ] have been sent
void updateADC(){
  updateFlag = false;
  if(colA0 > 0){
    voltage1 = DIV_1 * float(analogRead(A0)) * V_REF/1023.0;
    lcd.setCursor(colA0, rowA0);
    lcd.print(voltage1, 3);
  }
  if(colA1 > 0){
    voltage2 = DIV_2 * float(analogRead(A1)) * V_REF/1023.0;
    lcd.setCursor(colA1, rowA1);
    lcd.print(voltage2, 3);
  }
}

//the main loop is now just the hacked version of the Arduino Smartie code
void loop(){
  rxbyte = serial_getch();   //this calls the 'function' serial_getch(), stores result in rxbyte
  if (rxbyte == 254)     //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
  {
    ignoreCNT == 0;          //turn off character ignoring whenever a command is sent
    switch (serial_getch())  //calls serial_getch() to get the next byte from the PC
    {
    case 66: //former backlight on command
      break;
    case 70: //former backlight off command
      break;
    case 71:  //set cursor position
      MSGtime = millis();           //remember time that cursor cmd was sent
      updateFlag = true;            //set flag to update ADC readings
      row = 0;
      col = 0;
      temp = (serial_getch() - 1);  //get column byte
      switch (serial_getch())       //get row byte
      {
        //line 1 is already set up
      case 2:
        row = 1;
        temp += 0x40;
        break;
      case 3:
        row = 2;
        temp += 0x14;
        break;
      case 4:
        row = 3;
        temp += 0x54;
        break;
      default:
        break;
      }
      lcd.command(0b10000000 + temp);
      break;
    case 72:  //cursor home (reset display position)
      lcd.command(2);
      break;
    case 74:  //show underline cursor
      lcd.command(0b00001110);
      break;
    case 75:  //underline cursor off
    case 84:  //block cursor off
      lcd.command(0b00001100);
      break;
    case 76:  //move cursor left
      lcd.command(16);
      break;
    case 77:  //move cursor right
      lcd.command(20);
      break;
    case 78:  //define custom char
      lcd.command(64 + (serial_getch() * 8));  //get+set char address
      for (temp = 7; temp != 0; temp--)
      {
        lcd.print(serial_getch()); //get each pattern byte
      }
      break;
    case 83:  //show blinking block cursor
      lcd.command(0b00001111);
      break;
    case 86:  //GPO OFF
      //implement later
      break;
    case 87:  //GPO ON
      /*temp = serial_getch();
       if (temp == 1)
       {
       GPO1 = GPO_ON;
       }*/
      break;
    case 88:  //clear display, cursor home
      lcd.command(1);
      break;
    case 152: //set and remember (doesn't save value, though)
    case 153: //set backlight brightness
      //not implemented
      break;

      //these commands ignored (no parameters)
    case 35: //read serial number
    case 36: //read version number
    case 55: //read module type
    case 59: //exit flow-control mode
    case 65: //auto transmit keypresses
    case 96: //auto-repeat mode off (keypad)
    case 67: //auto line-wrap on
    case 68: //auto line-wrap off
    case 81: //auto scroll on
    case 82: //auto scroll off
    case 104: //init horiz bar graph
    case 109: //init med size digits
    case 115: //init narrow vert bar graph
    case 118: //init wide vert bar graph
      break;
    default:
      //all other commands ignored and parameter byte discarded
      temp = serial_getch();  //dump the command code
      break;
    }
    return;
  } //END OF COMMAND HANDLER

  //change accented char to plain, detect and change descenders
  //NB descenders only work on 5x10 displays. This lookup table works
  //  with my DEM-20845 (Display Elektronik GmbH) LCD using KS0066 chip.
  switch (rxbyte)
  {
    //chars that have direct equivalent in LCD charmap
    /* case 0x67: //g
     rxbyte = 0xE7;
     break;
     case 0x6A: //j
     rxbyte = 0xEA;
     break;
     case 0x70: //p
     rxbyte = 0xF0;
     break;
     case 0x71: //q
     rxbyte = 0xF1;
     break;
     case 0x79: //y
     rxbyte = 0xF9;
     break;
     */
  case 0x5B: //Formerly [, now does A0 ADC
    voltage1 = DIV_1 * float(analogRead(A0)) * V_REF/1023.0;           
    lcd.print(voltage1, 3);
    rxbyte = 0x76;           //will cause v to be displayed
    ignoreCNT = ignoreMAX;   //ignore characters replaced by ADC reading
    updateFlag = false;      //reset ADC update flag
    rowA0 = row;             //store row of A0 reading
    colA0 = col;             //store col of A0 reading
    break;
  case 0x5D: //Formerly ], now does A1 ADC
    voltage2 = DIV_2 * float(analogRead(A1)) * V_REF/1023.0;
    lcd.print(voltage2, 3);
    rxbyte = 0x76;           //will cause v to be displayed
    ignoreCNT = ignoreMAX;   //ignore characters replaced by ADC reading
    updateFlag = false;      //reset ADC update flag
    rowA1 = row;             //store row of A1 reading
    colA1 = col;             //store col of A1 reading
    break;
  case 0xE4: //ASCII "a" umlaut
    rxbyte = 0xE1;
    break;
  case 0xF1: //ASCII "n" tilde
    rxbyte = 0xEE;
    break;
  case 0xF6: //ASCII "o" umlaut
    rxbyte = 0xEF; //was wrong in v0.86
    break;
  case 0xFC: //ASCII "u" umlaut
    rxbyte = 0xF5;
    break;

    //accented -> plain equivalent
    //and misc symbol translation
  case 0xA3: //sterling (pounds)
    rxbyte = 0xED;
    break;
    /* case 0xB0: //degrees symbol
     rxbyte = 0xDF;
     break;
     */
  case 0xB5: //mu
    rxbyte = 0xE4;
    break;
  case 0xC0: //"A" variants
  case 0xC1:
  case 0xC2:
  case 0xC3:
  case 0xC4:
  case 0xC5:
    rxbyte = 0x41;
    break;
  case 0xC8: //"E" variants
  case 0xC9:
  case 0xCA:
  case 0xCB:
    rxbyte = 0x45;
    break;
  case 0xCC: //"I" variants
  case 0xCD:
  case 0xCE:
  case 0xCF:
    rxbyte = 0x49;
    break;
  case 0xD1: //"N" tilde -> plain "N"
    rxbyte = 0x43;
    break;
  case 0xD2: //"O" variants
  case 0xD3:
  case 0xD4:
  case 0xD5:
  case 0xD6:
  case 0xD8:
    rxbyte = 0x4F;
    break;
  case 0xD9: //"U" variants
  case 0xDA:
  case 0xDB:
  case 0xDC:
    rxbyte = 0x55;
    break;
  case 0xDD: //"Y" acute -> "Y"
    rxbyte = 0x59;
    break;
    /*  case 0xDF: //beta  //mucks up LCDSmartie's degree symbol??
     rxbyte = 0xE2;
     break;
     */
  case 0xE0: //"a" variants except umlaut
  case 0xE1:
  case 0xE2:
  case 0xE3:
  case 0xE5:
    rxbyte = 0x61;
    break;
  case 0xE7: //"c" cedilla -> "c"
    rxbyte = 0x63;
    break;
  case 0xE8: //"e" variants
  case 0xE9:
  case 0xEA:
  case 0xEB:
    rxbyte = 0x65;
    break;
  case 0xEC: //"i" variants
  case 0xED:
  case 0xEE:
  case 0xEF:
    rxbyte = 0x69;
    break;
  case 0xF2: //"o" variants except umlaut
  case 0xF3:
  case 0xF4:
  case 0xF5:
  case 0xF8:
    rxbyte = 0x6F;
    break;
  case 0xF7: //division symbol
    rxbyte = 0xFD;
    break;
  case 0xF9: //"u" variants except umlaut
  case 0xFA:
  case 0xFB:
    rxbyte = 0x75;
    break;
  default:
    break;
  }
  if(ignoreCNT > 0){
    ignoreCNT--;
  }
  if(ignoreCNT == 0){
    col++;              //increment column position counter
    lcd.write(rxbyte);  //otherwise a plain char so we print it to lcd
  }
}

So my problem right now is that the VCORE and VRIN values ([ and ] as the placeholders i believe) are showing wack values. They fluctuate, but they are not accurate.

I dont remember which is which, but [ and ] show ~1.692 and 1.602 respectively while VRIN and VCORE are really at 0.744v and 1.788v (verified with voltmeter). I measured VREF and it’s at 2.61, which I changed in the code above. So I don’t know why the voltmeter is wacked out.

I think there’s some code in there leftover for the servo and servo interrupt detection and turning off the lcd when power is not on analgoue 3 that are still in that code but I think these are easily solvable problems!

Bump, any ideas?

Silly question but are the voltages still wired into A0 and A1 ? Is the ground of the Arduino connected to the PC ground ?

No, I wired them to A2, A3, A4, vcore on A2, VRIN on A3. I’m guessing that means I didn’t change which analogue pins for the micro to read from but I’ve triend changing analogread_A0 to A2 and it’s not working.

The ground of the arduino and lcd and everything is all cross crossed a million times over.

Well somewhere here I have a Micro so I’ll dig it out and I’ll try your code and see what happens.

Fixed it! Had to replace basically all instances of A0/A1. I didn’t realize a lot of that stuff was referring to those pins. I thought they were something else, complicated. That was simple:

#include <LiquidCrystal.h>

//declare the constants to be used
#define LEDPIN 13             //pin attached to LED
#define servoPIN 9            //Servo control line
#define SWitchPIN 2           //input from N.O. momentary switch
#define redPIN 10             //PWM pin for red LED backlight
#define greenPIN 11           //PWM pin for green LED backlight
#define bluePIN 12            //PWM pin for blue LED backlight
#define rsPIN 8               //reset pin for LCD
#define enablePIN 3           //enable pin for LCD
#define d4PIN 4               //data pin4 for LCD
#define d5PIN 5               //data pin5 for LCD
#define d6PIN 6               //data pin6 for LCD
#define d7PIN 7               //data pin7 for LCD
// these constants won't change.  But you can change the size of
// your LCD using them:
const int numRows = 4;
const int numCols = 20;
const int ignoreMAX = 6;      //ignore this many characters
const unsigned long wait = 50;//wait time for ADC update after last Smartie cmd
#define posOpenCMD 1900       //Define Clockwise Servo position in usec
#define posCloseCMD 600       //Define CounterClockwise Servo position in usec
#define DBdelay 2000          //Min time needed btw any 2 button presses, in msec
#define fastSPD 100           //speed setting; 1 = slowest, 255 is fastest (???)
#define slowSPD 15            //Speed Servo/Door opens and closes (15 is good average)
#define DIV_1    1.0          //gain correction for A0 channel
#define DIV_2    1.0          //note it's 1.0, not 1, to get full floating point accuracy

#define V_REF    2.61         //use the measured Aref voltage

//declare the variables used
boolean updateFlag = false;          //flag to refresh ADC readings
volatile boolean doorOPEN = false;   //desired door state set to closed
byte rxbyte = 0;                     //rxbyte is the received byte from Smartie
byte temp = 0;
int ignoreCNT = 0;                   //count of characters to ignore
int row = 0;                         //index of last row position
int col = 0;                         //index of last col position
int rowA4 = 0;                       //index of A0 row position
int colA4 = 0;                       //index of A0 col position
int rowA3 = 0;                       //index of A1 row position
int colA3 = 0;                       //index of A1 col position
unsigned long MSGtime = 0;           //holds the time of the last cursor cmd
volatile unsigned long SWtime = 0;   //holds the time of the last valid switch push
float voltage1 = 0.0;                // calculated voltage for A0
float voltage2 = 0.0;                // calculated voltage for A1

LiquidCrystal lcd(rsPIN, enablePIN, d4PIN, d5PIN, d6PIN, d7PIN);


void setup() {
  //set the pins to be ins or outs
  pinMode(LEDPIN, OUTPUT);
  digitalWrite(LEDPIN, LOW);            //turn LED off
  pinMode(servoPIN, OUTPUT);
  pinMode(SWitchPIN, INPUT_PULLUP);
  pinMode(redPIN, OUTPUT);
  pinMode(greenPIN, OUTPUT);
  pinMode(bluePIN, OUTPUT);


  Serial.begin(9600);

  lcd.begin(numCols, numRows);
  delay(50);
  lcd.clear();
  delay(5);

  analogWrite(bluePIN,0);                //Blue brightness 255-0
  analogWrite(redPIN,255);               //Red brightness 255-0
  analogWrite(greenPIN,255);             //Green brightness 255-0

  analogReference(INTERNAL);              //use the internal 2.56v ADC reference

  //put a hello world on the LCD
  lcd.print("Line 1");
  lcd.setCursor(3, 1);
  lcd.print("Line 2");
  lcd.setCursor(8, 2);
  lcd.print("Line 3");
  lcd.setCursor(13, 3);
  lcd.print("Line 4");
  delay(2000);
}

//this function is used by the smartie code to get data from the PC
byte serial_getch(){
  int incoming;
  while (Serial.available()==0){
    //check to see if enough time has passed since last message from PC
    if((millis() - MSGtime > wait) && (updateFlag == true)){
      updateADC();
    }
  }
  // read the incoming byte:
  incoming = Serial.read();
  return (byte) (incoming &0xff);
}

//this function will update the ADC readings if the [ or ] have been sent
void updateADC(){
  updateFlag = false;
  if(colA4 > 0){
    voltage1 = DIV_1 * float(analogRead(A4)) * V_REF/1023.0;
    lcd.setCursor(colA4, rowA4);
    lcd.print(voltage1, 3);
  }
  if(colA3 > 0){
    voltage2 = DIV_2 * float(analogRead(A3)) * V_REF/1023.0;
    lcd.setCursor(colA3, rowA3);
    lcd.print(voltage2, 3);
  }
}

//the main loop is now just the hacked version of the Arduino Smartie code
void loop(){
  rxbyte = serial_getch();   //this calls the 'function' serial_getch(), stores result in rxbyte
  if (rxbyte == 254)     //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
  {
    ignoreCNT == 0;          //turn off character ignoring whenever a command is sent
    switch (serial_getch())  //calls serial_getch() to get the next byte from the PC
    {
    case 66: //former backlight on command
      break;
    case 70: //former backlight off command
      break;
    case 71:  //set cursor position
      MSGtime = millis();           //remember time that cursor cmd was sent
      updateFlag = true;            //set flag to update ADC readings
      row = 0;
      col = 0;
      temp = (serial_getch() - 1);  //get column byte
      switch (serial_getch())       //get row byte
      {
        //line 1 is already set up
      case 2:
        row = 1;
        temp += 0x40;
        break;
      case 3:
        row = 2;
        temp += 0x14;
        break;
      case 4:
        row = 3;
        temp += 0x54;
        break;
      default:
        break;
      }
      lcd.command(0b10000000 + temp);
      break;
    case 72:  //cursor home (reset display position)
      lcd.command(2);
      break;
    case 74:  //show underline cursor
      lcd.command(0b00001110);
      break;
    case 75:  //underline cursor off
    case 84:  //block cursor off
      lcd.command(0b00001100);
      break;
    case 76:  //move cursor left
      lcd.command(16);
      break;
    case 77:  //move cursor right
      lcd.command(20);
      break;
    case 78:  //define custom char
      lcd.command(64 + (serial_getch() * 8));  //get+set char address
      for (temp = 7; temp != 0; temp--)
      {
        lcd.print(serial_getch()); //get each pattern byte
      }
      break;
    case 83:  //show blinking block cursor
      lcd.command(0b00001111);
      break;
    case 86:  //GPO OFF
      //implement later
      break;
    case 87:  //GPO ON
      /*temp = serial_getch();
       if (temp == 1)
       {
       GPO1 = GPO_ON;
       }*/
      break;
    case 88:  //clear display, cursor home
      lcd.command(1);
      break;
    case 152: //set and remember (doesn't save value, though)
    case 153: //set backlight brightness
      //not implemented
      break;

      //these commands ignored (no parameters)
    case 35: //read serial number
    case 36: //read version number
    case 55: //read module type
    case 59: //exit flow-control mode
    case 65: //auto transmit keypresses
    case 96: //auto-repeat mode off (keypad)
    case 67: //auto line-wrap on
    case 68: //auto line-wrap off
    case 81: //auto scroll on
    case 82: //auto scroll off
    case 104: //init horiz bar graph
    case 109: //init med size digits
    case 115: //init narrow vert bar graph
    case 118: //init wide vert bar graph
      break;
    default:
      //all other commands ignored and parameter byte discarded
      temp = serial_getch();  //dump the command code
      break;
    }
    return;
  } //END OF COMMAND HANDLER

  //change accented char to plain, detect and change descenders
  //NB descenders only work on 5x10 displays. This lookup table works
  //  with my DEM-20845 (Display Elektronik GmbH) LCD using KS0066 chip.
  switch (rxbyte)
  {
    //chars that have direct equivalent in LCD charmap
    /* case 0x67: //g
     rxbyte = 0xE7;
     break;
     case 0x6A: //j
     rxbyte = 0xEA;
     break;
     case 0x70: //p
     rxbyte = 0xF0;
     break;
     case 0x71: //q
     rxbyte = 0xF1;
     break;
     case 0x79: //y
     rxbyte = 0xF9;
     break;
     */
  case 0x5B: //Formerly [, now does A0 ADC
    voltage1 = DIV_1 * float(analogRead(A4)) * V_REF/1023.0;           
    lcd.print(voltage1, 3);
    rxbyte = 0x76;           //will cause v to be displayed
    ignoreCNT = ignoreMAX;   //ignore characters replaced by ADC reading
    updateFlag = false;      //reset ADC update flag
    rowA4 = row;             //store row of A0 reading
    colA4 = col;             //store col of A0 reading
    break;
  case 0x5D: //Formerly ], now does A1 ADC
    voltage2 = DIV_2 * float(analogRead(A3)) * V_REF/1023.0;
    lcd.print(voltage2, 3);
    rxbyte = 0x76;           //will cause v to be displayed
    ignoreCNT = ignoreMAX;   //ignore characters replaced by ADC reading
    updateFlag = false;      //reset ADC update flag
    rowA3 = row;             //store row of A1 reading
    colA3 = col;             //store col of A1 reading
    break;
  case 0xE4: //ASCII "a" umlaut
    rxbyte = 0xE1;
    break;
  case 0xF1: //ASCII "n" tilde
    rxbyte = 0xEE;
    break;
  case 0xF6: //ASCII "o" umlaut
    rxbyte = 0xEF; //was wrong in v0.86
    break;
  case 0xFC: //ASCII "u" umlaut
    rxbyte = 0xF5;
    break;

    //accented -> plain equivalent
    //and misc symbol translation
  case 0xA3: //sterling (pounds)
    rxbyte = 0xED;
    break;
    /* case 0xB0: //degrees symbol
     rxbyte = 0xDF;
     break;
     */
  case 0xB5: //mu
    rxbyte = 0xE4;
    break;
  case 0xC0: //"A" variants
  case 0xC1:
  case 0xC2:
  case 0xC3:
  case 0xC4:
  case 0xC5:
    rxbyte = 0x41;
    break;
  case 0xC8: //"E" variants
  case 0xC9:
  case 0xCA:
  case 0xCB:
    rxbyte = 0x45;
    break;
  case 0xCC: //"I" variants
  case 0xCD:
  case 0xCE:
  case 0xCF:
    rxbyte = 0x49;
    break;
  case 0xD1: //"N" tilde -> plain "N"
    rxbyte = 0x43;
    break;
  case 0xD2: //"O" variants
  case 0xD3:
  case 0xD4:
  case 0xD5:
  case 0xD6:
  case 0xD8:
    rxbyte = 0x4F;
    break;
  case 0xD9: //"U" variants
  case 0xDA:
  case 0xDB:
  case 0xDC:
    rxbyte = 0x55;
    break;
  case 0xDD: //"Y" acute -> "Y"
    rxbyte = 0x59;
    break;
    /*  case 0xDF: //beta  //mucks up LCDSmartie's degree symbol??
     rxbyte = 0xE2;
     break;
     */
  case 0xE0: //"a" variants except umlaut
  case 0xE1:
  case 0xE2:
  case 0xE3:
  case 0xE5:
    rxbyte = 0x61;
    break;
  case 0xE7: //"c" cedilla -> "c"
    rxbyte = 0x63;
    break;
  case 0xE8: //"e" variants
  case 0xE9:
  case 0xEA:
  case 0xEB:
    rxbyte = 0x65;
    break;
  case 0xEC: //"i" variants
  case 0xED:
  case 0xEE:
  case 0xEF:
    rxbyte = 0x69;
    break;
  case 0xF2: //"o" variants except umlaut
  case 0xF3:
  case 0xF4:
  case 0xF5:
  case 0xF8:
    rxbyte = 0x6F;
    break;
  case 0xF7: //division symbol
    rxbyte = 0xFD;
    break;
  case 0xF9: //"u" variants except umlaut
  case 0xFA:
  case 0xFB:
    rxbyte = 0x75;
    break;
  default:
    break;
  }
  if(ignoreCNT > 0){
    ignoreCNT--;
  }
  if(ignoreCNT == 0){
    col++;              //increment column position counter
    lcd.write(rxbyte);  //otherwise a plain char so we print it to lcd
  }
}

Now just to get the trinket with varspeedservo working and my pc will basically be done! Just gotta get back to overclocking and mining.

Nice!

Psst. I got another thing for LCD Smartie. How to display hash rate for mining like GUIminer?

Do LCD screens go bad? On my 20x4 RGB, the top left two lines is bad 8 characters in, like it’s oddly dim. All other characters are fine, even if I take the text I have and move it over.

Is that a wiring problem? Really doesn’t seem like a wiring problem…

Belial88:
Do LCD screens go bad?

Yup and your description sounds like a bad LCD. Did it get squeezed or wet ? Too hot maybe ?

god dangit. Nothing happened, I have no idea why. UGH. All that rewiring is gonna be a massive PITA.

Okay… been a while, replaced LCD, trying to get this working. I have all the parts, but I had to do a fresh reinstall so it was a bit confusing on getting all the programs and stuff back…

#include <LiquidCrystal.h>

//declare the constants to be used
#define LEDPIN 13             //pin attached to LED
#define servoPIN 9            //Servo control line
#define SWitchPIN 2           //input from N.O. momentary switch
#define redPIN 10             //PWM pin for red LED backlight
#define greenPIN 11           //PWM pin for green LED backlight
#define bluePIN 12            //PWM pin for blue LED backlight
#define rsPIN 8               //reset pin for LCD
#define enablePIN 3           //enable pin for LCD
#define d4PIN 4               //data pin4 for LCD
#define d5PIN 5               //data pin5 for LCD
#define d6PIN 6               //data pin6 for LCD
#define d7PIN 7               //data pin7 for LCD
// these constants won't change.  But you can change the size of
// your LCD using them:
const int numRows = 4;
const int numCols = 20;
const int ignoreMAX = 6;      //ignore this many characters
const unsigned long wait = 50;//wait time for ADC update after last Smartie cmd
#define posOpenCMD 1900       //Define Clockwise Servo position in usec
#define posCloseCMD 600       //Define CounterClockwise Servo position in usec
#define DBdelay 2000          //Min time needed btw any 2 button presses, in msec
#define fastSPD 100           //speed setting; 1 = slowest, 255 is fastest (???)
#define slowSPD 15            //Speed Servo/Door opens and closes (15 is good average)
#define DIV_1    1.0          //gain correction for A0 channel
#define DIV_2    1.0          //note it's 1.0, not 1, to get full floating point accuracy

#define V_REF    2.61         //use the measured Aref voltage

//declare the variables used
boolean updateFlag = false;          //flag to refresh ADC readings
volatile boolean doorOPEN = false;   //desired door state set to closed
byte rxbyte = 0;                     //rxbyte is the received byte from Smartie
byte temp = 0;
int ignoreCNT = 0;                   //count of characters to ignore
int row = 0;                         //index of last row position
int col = 0;                         //index of last col position
int rowA4 = 0;                       //index of A0 row position
int colA4 = 0;                       //index of A0 col position
int rowA3 = 0;                       //index of A1 row position
int colA3 = 0;                       //index of A1 col position
unsigned long MSGtime = 0;           //holds the time of the last cursor cmd
volatile unsigned long SWtime = 0;   //holds the time of the last valid switch push
float voltage1 = 0.0;                // calculated voltage for A0
float voltage2 = 0.0;                // calculated voltage for A1

LiquidCrystal lcd(rsPIN, enablePIN, d4PIN, d5PIN, d6PIN, d7PIN);


void setup() {
  //set the pins to be ins or outs
  pinMode(LEDPIN, OUTPUT);
  digitalWrite(LEDPIN, LOW);            //turn LED off
  pinMode(servoPIN, OUTPUT);
  pinMode(SWitchPIN, INPUT_PULLUP);
  pinMode(redPIN, OUTPUT);
  pinMode(greenPIN, OUTPUT);
  pinMode(bluePIN, OUTPUT);


  Serial.begin(9600);

  lcd.begin(numCols, numRows);
  delay(50);
  lcd.clear();
  delay(5);

  analogWrite(bluePIN,0);                //Blue brightness 255-0
  analogWrite(redPIN,255);               //Red brightness 255-0
  analogWrite(greenPIN,255);             //Green brightness 255-0

  analogReference(INTERNAL);              //use the internal 2.56v ADC reference

  //put a hello world on the LCD
  lcd.print("Line 1");
  lcd.setCursor(3, 1);
  lcd.print("Line 2");
  lcd.setCursor(8, 2);
  lcd.print("Line 3");
  lcd.setCursor(13, 3);
  lcd.print("Line 4");
  delay(2000);
}

//this function is used by the smartie code to get data from the PC
byte serial_getch(){
  int incoming;
  while (Serial.available()==0){
    //check to see if enough time has passed since last message from PC
    if((millis() - MSGtime > wait) && (updateFlag == true)){
      updateADC();
    }
  }
  // read the incoming byte:
  incoming = Serial.read();
  return (byte) (incoming &0xff);
}

//this function will update the ADC readings if the [ or ] have been sent
void updateADC(){
  updateFlag = false;
  if(colA4 > 0){
    voltage1 = DIV_1 * float(analogRead(A4)) * V_REF/1023.0;
    lcd.setCursor(colA4, rowA4);
    lcd.print(voltage1, 3);
  }
  if(colA3 > 0){
    voltage2 = DIV_2 * float(analogRead(A3)) * V_REF/1023.0;
    lcd.setCursor(colA3, rowA3);
    lcd.print(voltage2, 3);
  }
}

//the main loop is now just the hacked version of the Arduino Smartie code
void loop(){
  rxbyte = serial_getch();   //this calls the 'function' serial_getch(), stores result in rxbyte
  if (rxbyte == 254)     //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
  {
    ignoreCNT == 0;          //turn off character ignoring whenever a command is sent
    switch (serial_getch())  //calls serial_getch() to get the next byte from the PC
    {
    case 66: //former backlight on command
      break;
    case 70: //former backlight off command
      break;
    case 71:  //set cursor position
      MSGtime = millis();           //remember time that cursor cmd was sent
      updateFlag = true;            //set flag to update ADC readings
      row = 0;
      col = 0;
      temp = (serial_getch() - 1);  //get column byte
      switch (serial_getch())       //get row byte
      {
        //line 1 is already set up
      case 2:
        row = 1;
        temp += 0x40;
        break;
      case 3:
        row = 2;
        temp += 0x14;
        break;
      case 4:
        row = 3;
        temp += 0x54;
        break;
      default:
        break;
      }
      lcd.command(0b10000000 + temp);
      break;
    case 72:  //cursor home (reset display position)
      lcd.command(2);
      break;
    case 74:  //show underline cursor
      lcd.command(0b00001110);
      break;
    case 75:  //underline cursor off
    case 84:  //block cursor off
      lcd.command(0b00001100);
      break;
    case 76:  //move cursor left
      lcd.command(16);
      break;
    case 77:  //move cursor right
      lcd.command(20);
      break;
    case 78:  //define custom char
      lcd.command(64 + (serial_getch() * 8));  //get+set char address
      for (temp = 7; temp != 0; temp--)
      {
        lcd.print(serial_getch()); //get each pattern byte
      }
      break;
    case 83:  //show blinking block cursor
      lcd.command(0b00001111);
      break;
    case 86:  //GPO OFF
      //implement later
      break;
    case 87:  //GPO ON
      /*temp = serial_getch();
       if (temp == 1)
       {
       GPO1 = GPO_ON;
       }*/
      break;
    case 88:  //clear display, cursor home
      lcd.command(1);
      break;
    case 152: //set and remember (doesn't save value, though)
    case 153: //set backlight brightness
      //not implemented
      break;

      //these commands ignored (no parameters)
    case 35: //read serial number
    case 36: //read version number
    case 55: //read module type
    case 59: //exit flow-control mode
    case 65: //auto transmit keypresses
    case 96: //auto-repeat mode off (keypad)
    case 67: //auto line-wrap on
    case 68: //auto line-wrap off
    case 81: //auto scroll on
    case 82: //auto scroll off
    case 104: //init horiz bar graph
    case 109: //init med size digits
    case 115: //init narrow vert bar graph
    case 118: //init wide vert bar graph
      break;
    default:
      //all other commands ignored and parameter byte discarded
      temp = serial_getch();  //dump the command code
      break;
    }
    return;
  } //END OF COMMAND HANDLER

  //change accented char to plain, detect and change descenders
  //NB descenders only work on 5x10 displays. This lookup table works
  //  with my DEM-20845 (Display Elektronik GmbH) LCD using KS0066 chip.
  switch (rxbyte)
  {
    //chars that have direct equivalent in LCD charmap
    /* case 0x67: //g
     rxbyte = 0xE7;
     break;
     case 0x6A: //j
     rxbyte = 0xEA;
     break;
     case 0x70: //p
     rxbyte = 0xF0;
     break;
     case 0x71: //q
     rxbyte = 0xF1;
     break;
     case 0x79: //y
     rxbyte = 0xF9;
     break;
     */
  case 0x5B: //Formerly [, now does A0 ADC
    voltage1 = DIV_1 * float(analogRead(A4)) * V_REF/1023.0;           
    lcd.print(voltage1, 3);
    rxbyte = 0x76;           //will cause v to be displayed
    ignoreCNT = ignoreMAX;   //ignore characters replaced by ADC reading
    updateFlag = false;      //reset ADC update flag
    rowA4 = row;             //store row of A0 reading
    colA4 = col;             //store col of A0 reading
    break;
  case 0x5D: //Formerly ], now does A1 ADC
    voltage2 = DIV_2 * float(analogRead(A3)) * V_REF/1023.0;
    lcd.print(voltage2, 3);
    rxbyte = 0x76;           //will cause v to be displayed
    ignoreCNT = ignoreMAX;   //ignore characters replaced by ADC reading
    updateFlag = false;      //reset ADC update flag
    rowA3 = row;             //store row of A1 reading
    colA3 = col;             //store col of A1 reading
    break;
  case 0xE4: //ASCII "a" umlaut
    rxbyte = 0xE1;
    break;
  case 0xF1: //ASCII "n" tilde
    rxbyte = 0xEE;
    break;
  case 0xF6: //ASCII "o" umlaut
    rxbyte = 0xEF; //was wrong in v0.86
    break;
  case 0xFC: //ASCII "u" umlaut
    rxbyte = 0xF5;
    break;

    //accented -> plain equivalent
    //and misc symbol translation
  case 0xA3: //sterling (pounds)
    rxbyte = 0xED;
    break;
    /* case 0xB0: //degrees symbol
     rxbyte = 0xDF;
     break;
     */
  case 0xB5: //mu
    rxbyte = 0xE4;
    break;
  case 0xC0: //"A" variants
  case 0xC1:
  case 0xC2:
  case 0xC3:
  case 0xC4:
  case 0xC5:
    rxbyte = 0x41;
    break;
  case 0xC8: //"E" variants
  case 0xC9:
  case 0xCA:
  case 0xCB:
    rxbyte = 0x45;
    break;
  case 0xCC: //"I" variants
  case 0xCD:
  case 0xCE:
  case 0xCF:
    rxbyte = 0x49;
    break;
  case 0xD1: //"N" tilde -> plain "N"
    rxbyte = 0x43;
    break;
  case 0xD2: //"O" variants
  case 0xD3:
  case 0xD4:
  case 0xD5:
  case 0xD6:
  case 0xD8:
    rxbyte = 0x4F;
    break;
  case 0xD9: //"U" variants
  case 0xDA:
  case 0xDB:
  case 0xDC:
    rxbyte = 0x55;
    break;
  case 0xDD: //"Y" acute -> "Y"
    rxbyte = 0x59;
    break;
    /*  case 0xDF: //beta  //mucks up LCDSmartie's degree symbol??
     rxbyte = 0xE2;
     break;
     */
  case 0xE0: //"a" variants except umlaut
  case 0xE1:
  case 0xE2:
  case 0xE3:
  case 0xE5:
    rxbyte = 0x61;
    break;
  case 0xE7: //"c" cedilla -> "c"
    rxbyte = 0x63;
    break;
  case 0xE8: //"e" variants
  case 0xE9:
  case 0xEA:
  case 0xEB:
    rxbyte = 0x65;
    break;
  case 0xEC: //"i" variants
  case 0xED:
  case 0xEE:
  case 0xEF:
    rxbyte = 0x69;
    break;
  case 0xF2: //"o" variants except umlaut
  case 0xF3:
  case 0xF4:
  case 0xF5:
  case 0xF8:
    rxbyte = 0x6F;
    break;
  case 0xF7: //division symbol
    rxbyte = 0xFD;
    break;
  case 0xF9: //"u" variants except umlaut
  case 0xFA:
  case 0xFB:
    rxbyte = 0x75;
    break;
  default:
    break;
  }
  if(ignoreCNT > 0){
    ignoreCNT--;
  }
  if(ignoreCNT == 0){
    col++;              //increment column position counter
    lcd.write(rxbyte);  //otherwise a plain char so we print it to lcd
  }
}

I can’t figure out how to change the servo position. RIght now it says

#define posOpenCMD 1900       //Define Clockwise Servo position in usec
#define posCloseCMD 600       //Define CounterClockwise Servo position in usec

To define servo positions, but I need to change it so it isnt opening as far. When I change it to like 1700, 1500, it doesnt do anything. I know it’s uploading the code because I mess with the lcd.print stuff.

Having a bit of trouble fighting lcd smartie, i think i can figure it back out again. Forgot how to do hwinfo, and all the pages on how to do it no longer exist… quite frustrating.

I haven’t seen Mee_n_Mac for a couple weeks. Hopefully he’s just on vacation or something.

I’ve not been following your project in detail, but I took a quick look at the code you posted on 4/24. I see the posOpenCMD definition and I see where the servo pin is defined and set up, but neither pin nor command are used anywhere in the loop() code. So if that is all the code, changing the value of posOpenCMD doesn’t do anything because it is never used anywhere. All the code that I see has to do with driving the LCD. I don’t see any code for manipulating the door.

  • Chip