Show Posts
|
|
Pages: [1]
|
|
2
|
Using Arduino / Programming Questions / Re: Touch process code stops voltage reference from working
|
on: December 02, 2012, 09:37:58 am
|
No. Each tab refers to a new file. You are using the IDE properly, and quite well. Ok, thanks Why are the status bars drawn using code in the Bikeduino.ino file, instead of in a function in the drawpage.ino file? It was something i did while trying to figure out what was stopping the voltage code from working, quite clearly wasn't that and just didn't change it back to using the drawpage.ino, have change it know you should simply remove the infinite loop from touch() not sure i follow and how to go about it
|
|
|
|
|
5
|
Using Arduino / Programming Questions / Touch process code stops voltage reference from working
|
on: December 02, 2012, 07:02:29 am
|
i have been wondering why my voltage reference code wasn't working when included into my main code, when it works fine run on its own, i have broken my project and find that when i don't call the code to process the touches on the the touchscreen that the voltage reference works fine. But i can't see why the touch code stops the voltage code from running See below for system setup and voltage code // web: http://www.henningkarlsen.com/electronics // //
#include <UTFT.h> #include <ITDB02_Touch.h> #include <avr/pgmspace.h> #include <drawpage> #include <touch> #include <gps> #include <Servo.h> Servo servoMain; // Define our Servo
#include <Adafruit_GPS.h> #if ARDUINO >= 100 #include <SoftwareSerial.h> #else // Older Arduino IDE requires NewSoftSerial, download from: // http://arduiniana.org/libraries/newsoftserial/ #include <NewSoftSerial.h> // DO NOT install NewSoftSerial if using Arduino 1.0 or later! #endif Adafruit_GPS GPS(&Serial1); // Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console // Set to 'true' if you want to debug and listen to the raw GPS sentences #define GPSECHO true
// this keeps track of whether we're using the interrupt // off by default! boolean usingInterrupt = false; void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
// Declare which fonts/icons to be using extern uint8_t BigFont[]; extern uint8_t SmallFont[]; extern uint8_t SevenSegNumFont[]; extern unsigned int down[576]; extern unsigned int up[576]; const int systembattpin = A8; // pin that the sensor is attached to const int controlbattpin = A9; float voltage1; float voltage2; int pos = 60;
// Uncomment the next two lines for the ITDB02 Mega Shield UTFT myGLCD(ITDB32S,38,39,40,41); // Remember to add ASPECT_16x9 if you are using an ITDB02-3.2WC! ITDB02_Touch myTouch(6,5,4,3,2);
int x, y; int page = 0;
void setup() { //////////////////////////gps setup/////////////////////////////// // connect at 115200 so we can read the GPS fast enough and echo without dropping chars // also spit it out Serial.begin(115200); Serial.println("Adafruit GPS library basic test!");
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800 GPS.begin(9600); // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); // uncomment this line to turn on only the "minimum recommended" data //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY); // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since // the parser doesn't care about other sentences at this time // Set the update rate GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate // For the parsing code to work nicely and have time to sort thru the data, and // print it out we don't suggest using anything higher than 1 Hz
// the nice thing about this code is you can have a timer0 interrupt go off // every 1 millisecond, and read data from the GPS for you. that makes the // loop code a heck of a lot easier! useInterrupt(true);
delay(1000); // Ask for firmware version Serial.println(PMTK_Q_RELEASE); ///////////////////////////////////////////////////////////////////////////// servoMain.attach(8); // servo on digital pin 8 // Initial setup myGLCD.InitLCD(PORTRAIT); myGLCD.clrScr(); myTouch.InitTouch(PORTRAIT); //LANDSCAPE myTouch.setPrecision(PREC_HI); box(); mainscr(); ////////////////////////Status bars///////////////////////////////////////// myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (0, 26, 239, 0); myGLCD.fillRoundRect (0, 26, 239, 0); myGLCD.setFont(SmallFont); myGLCD.setColor(0, 0, 255); myGLCD.setBackColor(255, 255, 255); myGLCD.print("Bike System", CENTER, 2); myGLCD.print("20:05:30", 10, 14); myGLCD.print("12/09/12", 170, 14); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (0, 293, 239, 319); myGLCD.fillRoundRect (0, 293, 239, 319); myGLCD.setFont(SmallFont); myGLCD.setColor(0, 0, 255); myGLCD.setBackColor(255, 255, 255); myGLCD.print("Battery status", CENTER, 294); myGLCD.print("System", 4, 306); myGLCD.print("Control", 130, 306); myGLCD.setColor(255, 0, 0); myGLCD.print("v", 95, 306); myGLCD.print("v", 225, 306); ///////////////////////////////////////////////////////////////////////////// page = 0; }
void getbattstatus() { // read the input on analog pin 8: int sensorValue = analogRead(A8); // read the input on analog pin 9: int sensorValue1 = analogRead(A9); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 8.4V): float voltage1 = ((sensorValue * 1.68) * (5.0 / 1023.0)); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 8.4V): float voltage2 = ((sensorValue * 1.68) * (5.0 / 1023.0)); myGLCD.setFont(SmallFont); myGLCD.setColor(255, 0, 0);
myGLCD.printNumF(voltage1, 1, 60, 306, '.', 3, ' '); myGLCD.printNumF(voltage2, 1, 190, 306, '.', 3, ' '); }
void loop() { getbattstatus(); gpsloop(); }
the touch process code is on a separate tab and i have been calling in the void loop() using touch(); see touch code below void touch() { while (true) { if (myTouch.dataAvailable())
{ myTouch.read(); x=myTouch.getX(); y=myTouch.getY();
//page 0 - Main menu
if (page == 0){
//Button: Go Ride if ((y>=40) && (y<=110) && (x>=0) && (x<=239)){ page = 1; box(); ridescr(); }
//Button: Settings else if ((y>=130) && (y<=200) && (x>=0) && (x<=239)){ page = 2; box(); settingsscr(); }
//Button: About else if ((y>=220) && (y<=290) && (x>=0) && (x<=239)){ page = 3; box(); aboutscr(); } }
// page 1 - Go ride if (page == 1){
//122, 116, 234, 200 125/140 button if ((y>=116) && (y<=200) && (x>=122) && (x<=234)){ servoMain.write(180); } } // page 2 - Settings
if (page == 2){
//button1 5, 29, 117, 111 if ((y>=29) && (y<=111) && (x>=5) && (x<=117)){ page = 4; box(); stsb1(); }
//button2 122, 29, 234, 111 else if ((y>=29) && (y<=111) && (x>=122) && (x<=234)){ page = 5; box(); stsb2(); }
//button3 else if ((y>=27) && (y<=111) && (x>=5) && (x<=117)){ page = 6; box(); stsb3(); }
//button4 else if ((y>=27) && (y<=111) && (x>=5) && (x<=117)){ page = 7; box(); stsb4(); }
//button5 else if ((y>=27) && (y<=111) && (x>=5) && (x<=117)){ page = 8; box(); stsb5(); }
//button6 122, 205, 234, 289 else if ((y>=205) && (y<=289) && (x>=122) && (x<=234)){ page = 9; box(); stsb6(); } }
if (page != 0){
//Return to main screen button used on all screens if ((y>=0) && (y<=239) && (x>=0) && (x<=22)){ page = 0; box(); mainscr(); } else if (page == 0){ myGLCD.setColor(255, 255, 255); myGLCD.setBackColor(255, 0, 0); myGLCD.drawRoundRect (0, 26, 239, 0); myGLCD.fillRoundRect (0, 26, 239, 0); delay (4000); // statusbar1(); } } } } }
Any help would be appreciated
|
|
|
|
|
6
|
Using Arduino / Programming Questions / integrating voltage ref code (or other variables) into touch screen code
|
on: October 17, 2012, 03:49:02 pm
|
I have been trying to integrate my voltage reference code into my touch screen code, the voltage reading changes when a fresh page is loaded but not if left on one page and pot is adjusted. See voltage reference below, which when run on its own, the voltage displayed changes with the adjustment of the pot #include <UTFT.h>
extern uint8_t BigFont[]; const int systembattpin = A8; // pin that the sensor is attached to const int controlbattpin = A9; float voltage1 = 0; float voltage2 = 0;
UTFT myGLCD(ITDB32S,38,39,40,41);
int x, y;
void setup() { // Initial setup myGLCD.InitLCD(PORTRAIT); myGLCD.clrScr(); myGLCD.setBackColor(255, 255, 255); }
void loop() { // read the input on analog pin 8: int sensorValue = analogRead(A8); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage1 = ((sensorValue * 1.68) * (5.0 / 1023.0)); myGLCD.setFont(BigFont); myGLCD.setColor(0, 0, 255); myGLCD.print("System battery", CENTER, 50); myGLCD.printNumF(voltage1, 1, CENTER, 100, '.', 3, ' '); // read the input on analog pin 9: int sensorValue1 = analogRead(A9); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage2 = ((sensorValue * 1.68) * (5.0 / 1023.0)); myGLCD.setFont(BigFont); myGLCD.setColor(0, 0, 255); myGLCD.print("Control battery", CENTER, 150); myGLCD.printNumF(voltage2, 1, CENTER, 200, '.', 3, ' '); }
So why does this not happen when it is integrated into my main code? Is it the way i have constructed my menu code? Do i need function to check whether the voltage has changed and if so update/refresh? See main code attached, as its too long to post The voltage reading is calculated in void getbattstatus() which is called by void statusbar2(), is this the wrong way to go about it, any help would be grateful, as this will help with integrating time and date code Thanks in advance
|
|
|
|
|
7
|
Using Arduino / Displays / SOLVED - Touch screen menu
|
on: September 30, 2012, 09:38:32 am
|
I've been working on a menu for my touch screen, but i can't get the page mapping to work, so after going rom the main page to the settings page and pressing the top right button (which shares some x and y coordinates with a button on the main page) it carries out the action of the main page button. See code below // web: http://www.henningkarlsen.com/electronics // // // Remember to change the next line if you are using as 16bit module! #include <UTFT.h> #include <ITDB02_Touch.h>
// Declare which fonts/icons we will be using extern uint8_t BigFont[]; extern uint8_t SmallFont[]; extern uint8_t SevenSegNumFont[];
// Uncomment the next two lines for the ITDB02 Mega Shield UTFT myGLCD(ITDB32S,38,39,40,41); // Remember to add ASPECT_16x9 if you are using an ITDB02-3.2WC! ITDB02_Touch myTouch(6,5,4,3,2);
int x, y; int page = 0;
void setup() { // Initial setup myGLCD.InitLCD(PORTRAIT); myGLCD.clrScr(); myTouch.InitTouch(PORTRAIT); //LANDSCAPE myTouch.setPrecision(PREC_HI); mainscr(); statusbar1(); statusbar2(); page = 0; } void startupscr() { }
void statusbar1() //top status bar { myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (0, 22, 239, 0); myGLCD.fillRoundRect (0, 22, 239, 0); myGLCD.setFont(SmallFont); myGLCD.setColor(0, 0, 255); myGLCD.setBackColor(255, 255, 255); myGLCD.print("Bike System", CENTER, 0); myGLCD.print("15:35:44", 10, 10); myGLCD.print("12/09/12", 170, 10); } void statusbar2() //bottom status bar { myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (0, 295, 239, 319); myGLCD.fillRoundRect (0, 295, 239, 319); myGLCD.setFont(SmallFont); myGLCD.setColor(0, 0, 255); myGLCD.setBackColor(255, 255, 255); myGLCD.print("Battery status", CENTER, 296); myGLCD.print("System -", 4, 308); myGLCD.print("Control -", 140, 308); myGLCD.setColor(255, 0, 0); myGLCD.print("7.4v", 60, 308); myGLCD.print("8.0v", 200, 308); } void mainscr() { myGLCD.fillScr(0, 68, 0); myGLCD.setBackColor (0, 68, 0); myGLCD.setFont(BigFont); myGLCD.setColor(255, 255, 255); myGLCD.setBackColor (0, 0, 0); myGLCD.setColor(0, 0, 0); myGLCD.fillRoundRect (0, 40, 239, 110); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (0, 40, 239, 110); myGLCD.print("Go Ride", CENTER, 70); myGLCD.setColor(0, 0, 0); myGLCD.fillRoundRect (0, 130, 239, 200); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (0, 130, 239, 200); myGLCD.print("Settings", CENTER, 160); myGLCD.setColor(0, 0, 0); myGLCD.fillRoundRect (0, 220, 239, 290); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (0, 220, 239, 290); myGLCD.print("About", CENTER, 250); } void ridescr() { myGLCD.fillScr(0, 68, 0); myGLCD.setBackColor (0, 68, 0); myGLCD.setFont(SevenSegNumFont); myGLCD.setColor(255, 255, 255); myGLCD.print("25", 30, 60); } void settingsscr() { myGLCD.fillScr(0, 68, 0); myGLCD.setBackColor (0, 0, 0); myGLCD.setFont(BigFont); //sbutton1 myGLCD.setColor(0, 0, 0); myGLCD.fillRoundRect (5, 27, 117, 111); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (5, 27, 117, 111); myGLCD.print("TIME", 30, 60); //sbutton2 myGLCD.setColor(0, 0, 0); myGLCD.fillRoundRect (122, 27, 234, 111); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (122, 27, 234, 111); myGLCD.print("DATE", 145, 60); //sbutton3 myGLCD.setColor(0, 0, 0); myGLCD.fillRoundRect (5, 116, 117, 200); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (5, 116, 117, 200); myGLCD.print("USER", 30, 150); //sbutton4 myGLCD.setColor(0, 0, 0); myGLCD.fillRoundRect (122, 116, 234, 200); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (122, 116, 234, 200); myGLCD.print("????", 145, 150); //sbutton5 myGLCD.setColor(0, 0, 0); myGLCD.fillRoundRect (5, 205, 117, 289); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (5, 205, 117, 289); myGLCD.print("GPS", 35, 245); //sbutton6 myGLCD.setColor(0, 0, 0); myGLCD.fillRoundRect (122, 205, 234, 289); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (122, 205, 234, 289); myGLCD.print("????", 145, 245); }
void stsb1() { } void stsb2() { }
void stsb3() { } void stsb4() { } void stsb5() { }
void aboutscr() { }
void loop() { while (true) { if (myTouch.dataAvailable()) { myTouch.read(); x=myTouch.getX(); y=myTouch.getY(); //Button: Go Ride if ((y>=40) && (y<=110)) { if ((x>=0) && (x<=239)); page = 1; myGLCD.clrScr(); ridescr(); statusbar1(); statusbar2(); } //Button: Settings if ((y>=130) && (y<=200)) { if ((x>=0) && (x<=239)); page = 2; myGLCD.clrScr(); settingsscr(); statusbar1(); statusbar2(); } // settings page button actions 5, 27, 117, 111 if (page == 2){ //button1 if ((y>=27) && (y<=111) && (x>=5) && (x<=117)) { myGLCD.clrScr(); } } //Button: About if ((y>=220) && (y<=290)) { if ((x>=0) && (x<=239)); page = 3; myGLCD.clrScr(); statusbar1(); statusbar2(); aboutscr(); } //Return to main screen button used on all screens if ((y>=0) && (y<=239) && (x>=0) && (x<=22)) { page = 0; myGLCD.clrScr(); mainscr(); statusbar1(); statusbar2(); } //Power Button if ((y>=0) && (y<=239) && (x>=295) && (x<=319)) { myGLCD.lcdOff(); }
}}}
If someone could point me in the right direction and what i'm doing wrong, that would be great
|
|
|
|
|
8
|
Using Arduino / Displays / Re: Voltage reference with LCD
|
on: August 07, 2012, 04:07:55 pm
|
thanks for your input Doc, if i understand you correctly, your actually talking about turning off the lcd? this wouldn't fit with the overall view of how i what this piece of code to fit into the overall project that i have in mind, for example i would like to have my main code with this code sat in the background and only appearing for a set amount of time when the batt volt is below the threshold and then returning to the main display, run by the main code i have got the timer working, but lcd.clear() only half clears the display, unlike when the voltage returns above the threshold when the display clears completely any ideas code as it is now: - #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); boolean lowbatt = false; unsigned long Timer; //ALWAYS use unsigned long for timers, not int const int analogPin = A0; // pin that the sensor is attached to const int ledPin = 13; // pin that the LED is attached to const int threshold = 3; // an arbitrary threshold level that's in the range of the analog input void setup() { pinMode(ledPin, OUTPUT); // initialize serial communication at 9600 bits per second: Serial.begin(9600); // declare pin 9 to be an output: pinMode(6, OUTPUT); analogWrite(6, 90);//contrast // set up the LCD's number of columns and rows: lcd.begin(16, 2); } void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage = sensorValue * (5.0 / 1023.0); // if the analog value is low enough: if (voltage < threshold) { // If we currently have good battery, then make a note of when // we went bad! if ( lowbatt == false ) { Timer = millis(); //set timer } lcd.setCursor(1, 0); // Print a message to the LCD. lcd.print("Battery Volts"); // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(6, 1); // print voltage on A0: lcd.print(voltage); digitalWrite(ledPin, LOW); lowbatt = true;
} else { // This will clear the display if the voltage is great. So that's okay. digitalWrite(ledPin, HIGH); lcd.clear(); lowbatt = false; } // Now, let us clean the display if we are over the timer condition. if ( lowbatt == true ) { // So we know that the battery is flagged as low. // Check the timer to see if we want to clear the screen if (millis()-Timer >= 4000UL) { // Just clear the display! lcd.clear(); } } }
|
|
|
|
|
9
|
Using Arduino / Displays / Re: Voltage reference with LCD
|
on: August 06, 2012, 05:44:13 pm
|
I have attempted to add the flags into the current code as well as change delay for millis, but still can't get the LCD to clear after the the count and now the display is now faint and missing characters //Voltage reference code to display voltage on LCD it has fallen below the set threshold and for the time define by millis
// include the library code: #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
boolean lowbatt = false; unsigned long Timer; //ALWAYS use unsigned long for timers, not int const int analogPin = A0; // pin that the sensor is attached to const int ledPin = 13; // pin that the LED is attached to const int threshold = 3; // an arbitrary threshold level that's in the range of the analog input
void setup() { pinMode(ledPin, OUTPUT); // initialize serial communication at 9600 bits per second: Serial.begin(9600); // declare pin 9 to be an output: pinMode(6, OUTPUT); analogWrite(6, 90);//contrast // set up the LCD's number of columns and rows: lcd.begin(16, 2);
}
void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage = sensorValue * (5.0 / 1023.0); // if the analog value is low enough: if (voltage < threshold) { Timer = millis(); //set timer lcd.setCursor(1, 0); // Print a message to the LCD. lcd.print("Battery Volts"); // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(6, 1); // print voltage on A0: lcd.print(voltage); digitalWrite(ledPin, LOW); lowbatt = true; if (millis()-Timer >= 2500UL); //timer expired if (lowbatt = true); lcd.clear(); } else { digitalWrite(ledPin, HIGH); lcd.clear(); lowbatt = false; }
}
i can't work out if it the mills code or the setting of the flags thats wrong or am i missing something else
|
|
|
|
|
10
|
Using Arduino / Displays / Voltage reference with LCD
|
on: August 05, 2012, 05:16:14 pm
|
Hi I have my lcd setup to display voltage referenced on A0 input, for using a battery monitoring with my project, the idea is for the lcd to not display anything while the voltage is above the threshold of 3volts and then display the voltage for 2 seconds and then clear the lcd. After the voltage drops below the threshold and after the delay (have tried using delay and mills) i can't get the lcd to clear. See code /*
// include the library code: #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long time; const int analogPin = A0; // pin that the sensor is attached to const int ledPin = 13; // pin that the LED is attached to const int threshold = 3; // an arbitrary threshold level that's in the range of the analog input
void setup() { pinMode(ledPin, OUTPUT); // initialize serial communication at 9600 bits per second: Serial.begin(9600); // declare pin 9 to be an output: pinMode(6, OUTPUT); analogWrite(6, 90);//contrast // set up the LCD's number of columns and rows: lcd.begin(16, 2);
}
void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage = sensorValue * (5.0 / 1023.0); // if the analog value is high enough, turn on the LED: if (voltage < threshold) { lcd.setCursor(1, 0); // Print a message to the LCD. lcd.print("Battery Volts"); // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(6, 1); // print the number of seconds since reset: lcd.print(voltage); digitalWrite(ledPin, LOW); delay(2500); lcd.clear(); } else { digitalWrite(ledPin, HIGH); //lcd.clear(); }
}
The clear works fine, if the voltage goes back above 3 Any help would be appreciated.
|
|
|
|
|
11
|
Using Arduino / Displays / Re: LCD issue related to servo code??
|
on: July 28, 2012, 11:31:37 am
|
Hmmm, that reminds me, the Servo library has this warning:
The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins. On the Mega, up to 12 servos can be used without interfering with PWM functionality; use of 12 to 23 motors will disable PWM on pins 11 and 12.
The tutorial for LiquidCrystal says you should hook up the lcd to pin 9 with PWM. So you might need to rearrange the wiring to move the LiquidCrystal PWM to another PWM pin (3, 5, 6,or 11), but you may then have to move wires on other pins, to get to to one of the PWM pins. Thanks Michael, thats worked, just had to swap pin 9 to 6, thanks again
|
|
|
|
|