Show Posts
Pages: [1] 2 3
1  Using Arduino / Sensors / SOLVED: Re: LDR interfering with LM35 values on: December 16, 2012, 06:24:31 pm
Fixed my own problem. I simply connected a 10uf capacitor between Gnd and the Analog pin to act as a filter and this cleared up the problem.

Hope this helps someone else.
2  Using Arduino / Sensors / SOLVED: LDR interfering with LM35 values on: December 16, 2012, 04:54:08 pm
I have hooked up an LDR on A0 and a DFRobot LM35 block on A2 of my Arduino Mega.
The board is powered by an external 12V power source

With out the LDR plugged in my LM35 runs perfectly showing a steady temperature reading. As soon as I plug in the LDR my LM35 values go haywire.

I assume this is because the LM35 is very sensitive to changes in voltage.

I am connecting to the board using pyfirmata and firmata standard is installed on the board if that helps.

Questions:
is it imposible tot use the LM35 with an LDR? If so what would you reconmend as a replacement that is not affected by the LDR?
or
If I can use them together what do I need to do?

Thanks
Simon
3  Using Arduino / Displays / Re: Writing data from variable to GLCD. Getting errors on: April 27, 2011, 05:57:36 am
OK, I seem to have sorted it. I was not defining a text area. I assumed that by not defining an area, the GLCD would use the full area as the default text area. Once I defined
Code:
gText  textTop = gText(textAreaFULL);

and pre-pended all my other calls such as print with textTop I found the scrolling now works

Thanks
Simon
4  Using Arduino / Displays / Re: Writing data from variable to GLCD. Getting errors on: April 27, 2011, 03:25:30 am
The only way I can describe the symptom is that text starts from the top left of the display and fills all the way down to the bottom. If there is more text to come, I would expect the top line to be removed and all other lines move up one line to fill it's place and new text appear on the now empty bottom line.

Instead, when the text fills the screen down to the bottom right hand corner, the display clears it's self and the remaining text starts to be printed from the top left of the screen again.


I have tried to make a bit of graphic example below (LCD is bigger than this of course).

Imagine I am sending this text to the LCD
"This is some text that I have written to show what I have tried to put in words above. A picture is better than words."

Here is what I would expect
screen 1
|-----------------------------------|
|This is some text that I have   |
|written to show what i have    |
|tried to put in words above     |
|-----------------------------------|
screen 2
|-----------------------------------|
|written to show what i have    |
|tried to put in words above     |
|A picture is better than words |
|-----------------------------------|

Here is what I actually get

screen 1
|-----------------------------------|
|This is some text that I have   |
|written to show what i have    |
|tried to put in words above     |
|-----------------------------------|
screen 2
|-----------------------------------|
|A picture is better than words  |
|                                          |
|                                          |
|-----------------------------------|

Hope this makes it clearer what the problem is. As you can imagine, it makes it much harder to read the message when all the relevant text on previous lines (especially if it is mid sentence) has been removed.

Thanks
Simon
5  Using Arduino / Displays / Re: Writing data from variable to GLCD. Getting errors on: April 26, 2011, 07:53:39 am
Hi Bill, Here is the code I currently have loaded on my Arduino

If the first letter of the code received is a 't' then text is expected next and sent to the LCD. The problem as I mentioned is that any text larger than the display limit for the LCD is not scrolled, the LCD simply clears the screen and starts again from the top.

Can you see what the problem is which my code?

Thank you
Simon
Code:


//start GLCD
#include <glcd.h>
#include "fonts/allFonts.h"         // system and arial14 fonts are used
#include "bitmaps/allBitmaps.h"       // all images in the bitmap dir

String lcdText;
unsigned long startMillis;
unsigned int loops = 0;
unsigned int iter = 0;
//end GLCD

int unreadFlag; //1 = True, 0 = False
int  emailButtonState = 0;
char p;
void setup() {   
  GLCD.Init();   // initialise the library, non inverted writes pixels onto a clear screen 
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(8, OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(13,OUTPUT);
  pinMode(12,INPUT);
  Serial.begin(9600);
 
  //Start GLCD
  delay(500);                // allow time for LCD to reset
  GLCD.ClearScreen(); 
 
  GLCD.SelectFont(System5x7); // switch to fixed width system font
  GLCD.print("Welcome to i-Monitor\n\nSimon Carr");
  //End GLCD
}

void loop() {
if (Serial.available()>0)
{
  p = Serial.read();
 
 //p = Serial.read();
}

switch (p){
 case 'x':
  unreadOn();
  break;
 case 'o':
  unreadOff();
  break;
 case 'p':
  flashLED(10,1);
  break;
 case 'a':
  emailAlertOn();
  break;
 case 't':
  delay(100);
  lcdText = "";
  while (Serial.available()){
    p = Serial.read();
    lcdText += p;
  }
 
 
  GLCD.ClearScreen();
  GLCD.CursorToXY(0,0);
  GLCD.SelectFont(System5x7); // switch to fixed width system font
  GLCD.SetTextMode(SCROLL_UP);

  for (int x = 0; x < lcdText.length(); x++)
  {
  delay(50);
  GLCD.print(lcdText.substring(x,x+1));

  }
  break;

}
p=' ';
emailButtonState = digitalRead(12);
if (emailButtonState == HIGH && unreadFlag == 1){
  beep(1);
  unreadOff();
  emailAlertOf();
 
}
if (emailButtonState == HIGH){
   serialWrite('e'); //Instructs python script to open email program
   delay(2000);
}



}

void unreadOn(){
 if (unreadFlag == 0){
 digitalWrite(8,HIGH);
 flashBeep(2);
 unreadFlag = 1;
 }
 else{
  flashBeep(1);
 }
 
}

void unreadOff(){
 digitalWrite(8,LOW);
 unreadFlag = 0;
}

int flashLED(int pin, int times){
  for (int a=0;a<times;a++){
  digitalWrite(pin,HIGH);
  delay(250);
  digitalWrite(pin,LOW);
  delay(250);
  } 
}


int beep(int times){
for (int a=0;a<times;a++){
 digitalWrite(11, HIGH);
 delay(250);
 digitalWrite(11,LOW);
 delay(250);
}
}

int flashBeep(int times){
for (int a=0;a<times;a++){
 digitalWrite(9, HIGH);
 digitalWrite(11,HIGH);
 delay(250);
 digitalWrite(9,LOW);
 digitalWrite(11,LOW);
 delay(250);
}
}

char serialWrite(char data){
 Serial.write(data);
}

void emailAlertOn()
{
 digitalWrite(13,HIGH);
 flashBeep(3);
}

void emailAlertOf()
{
 digitalWrite(13,LOW);
}
6  Using Arduino / Displays / Re: Writing data from variable to GLCD. Getting errors on: April 25, 2011, 03:04:26 pm
Hope I am not starting to annoy anyone with all my questions. But.......

When I use the GLCD.SetTextMode(SCROLL_UP); (or SCROLL_DOWN) the LCD clears the screen as part of the scroll and starts again from the top. In order for users to read a long string of text, I am writing to the LCD in a teletype fashion that is slow enough to read, as long as the last text written scrolls up the screen, however as I just said it simply clears the screen.

Here is my code
Code:
GLCD.CursorToXY(1,1);
 
  GLCD.ClearScreen();
  GLCD.SetTextMode(SCROLL_UP);
  for (int x = 0; x < lcdText.length(); x++)
  {
  delay(50);
  GLCD.print(lcdText.substring(x,x+1));
  }

Is there a way to carry out a true scrolling of text.

Thanks
Simon
7  Using Arduino / Displays / Re: Writing data from variable to GLCD. Getting errors on: April 24, 2011, 08:32:32 am
Actually don't worry about my last post. Not sure why, but the /n escape code works fine when I send it from python via Serial. For some reason it just does not work when I send it from the Arduino Serial monitor

Thanks Anyway

Simon
8  Using Arduino / Displays / Re: Writing data from variable to GLCD. Getting errors on: April 24, 2011, 06:58:43 am
Hi Bill,

Just about there with my new project. One thing that I am still struggling with however is getting new lines to be displayed on the GLCD

The following code works just work
Code:
GLCD.SetTextMode(SCROLL_UP);
  GLCD.CursorToXY(1,1);
  GLCD.ClearScreen();
  GLCD.println("flkdsjk\nfjdslfjkdfj\ndlfkj\nlsdjf");
A line wrap replaces the \n escape code, however the following code just displays the \n as text
Code:
  while (Serial.available()){
    p = Serial.read();
    lcdText += p;
  }
 
  GLCD.SetTextMode(SCROLL_UP);
  GLCD.CursorToXY(1,1);
  GLCD.ClearScreen();
  GLCD.println(lcdText);
Any idea how I can get the escape codes to be recognized when read from serial?

Thanks
Simon
9  Using Arduino / Displays / Re: Writing data from variable to GLCD. Getting errors on: April 23, 2011, 04:59:58 pm
Hi Bill,

I very much appreciate your time. I feel a bit bad actually, because after your post I tried the print function and found it did not work, that lead me to realize that I was using the old library. Hope that I have not wasted too much of your time. As soon as I updated with the new GLCD library, I was able to print strings. I was only using char because it was the only option available in the library I had.

One other quick question. Is there any library out there which will allow me to supply a string of text and a maximum character width and have it return a string that is formated with line breaks so that line wraps do not occur in the middle of words?

Again, I (and I think everybody else) appreciates your time and effort on this library!

Simon
10  Using Arduino / Interfacing w/ Software on the Computer / Going beyond flashing an LED with Firmata on: April 23, 2011, 07:16:54 am
HI All,

I have not yet tried to use Firmata, but it sounds like it could be very useful. I would like to use it with Python, so I assume using pyduino would be the way to go.

Having read a few forum posts and looked at a few web sites, I see that Firmata and pyduino could help me flash some LED's and perhaps turn on a motor, but what I also need is to write to an LCD panel. Some searching on Google and I found a post that suggested that you would need to write your own firmware and protocol to achieve this.

Hoping that someone can tell me that this is not correct and there is an easy way to achieve this.

Thanks
Simon
11  Using Arduino / Displays / Writing data from variable to GLCD. Getting errors on: April 23, 2011, 07:09:38 am
Hi All,

I have a a QY-12864F GLCD panel. Using the example script that comes with the GLCD library works just fine. However any text it writes to the script i.e.
Code:
GLCD.Puts("GLCD  version );
Is just text and yes it works fine.
When I try to replace this with a variable. I.E.
Code:
String glcdVersion = "GLCD version ";
GLCD.Puts(glcdVersion);
I get the following error when I try to compile

 error: no matching function for call to 'ks0108::Puts(String&)'

Can anyone provide any advice on how to write a string variable to a GLCD using the GLCD library

Thanks Simon
12  Using Arduino / Motors, Mechanics, and Power / Confused about how to use a stepper motor on: January 28, 2011, 10:52:26 am
Hi,

I am using the following stepper motor. I have a stepper motor driver which can drive two stepper motors. There are 4 connections for each motor. This stepper motor however has eight wires. Can anyone help me on how to connect my stepper motor to the driver.

This is my motor driver http://www.emartee.com/product/41468/Arduino-Motor-Drive-Shield
This is my Stepper motor http://www.diycnc.co.uk/my103h702.pdf

Can someone help me with which wires go into which ports and point me in the write direction of how I control the motor with Arudino code.

Thanks
Simon
13  Forum 2005-2010 (read only) / Syntax & Programs / Help! What am I doing wrong on: January 16, 2011, 06:35:40 am
HI I am trying to use the sleep function discussed at the following URL

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1292898715

Here is the full code
Code:
#include <avr/sleep.h>
#include <avr/wdt.h>

long timeSleep = 0;  // total time due to sleep
float calibv = 0.93; // ratio of real clock with WDT clock
volatile byte isrcalled = 0;  // WDT vector flag

// Internal function: Start watchdog timer
// byte psVal - Prescale mask
void WDT_On (byte psVal)
{
  // prepare timed sequence first
  byte ps = (psVal | (1<<WDIE)) & ~(1<<WDE);
  cli();
  wdt_reset();
  /* Clear WDRF in MCUSR */
  MCUSR &= ~(1<<WDRF);
  // start timed sequence
  WDTCSR |= (1<<WDCE) | (1<<WDE);
  // set new watchdog timeout value
  WDTCSR = ps;
  sei();
}

// Internal function.  Stop watchdog timer
void WDT_Off() {
  cli();
  wdt_reset();
  /* Clear WDRF in MCUSR */
  MCUSR &= ~(1<<WDRF);
  /* Write logical one to WDCE and WDE */
  /* Keep old prescaler setting to prevent unintentional time-out */
  WDTCSR |= (1<<WDCE) | (1<<WDE);
  /* Turn off WDT */
  WDTCSR = 0x00;
  sei();
}

// Calibrate watchdog timer with millis() timer(timer0)
void calibrate() {
  // timer0 continues to run in idle sleep mode
  set_sleep_mode(SLEEP_MODE_IDLE);
  long tt1=millis();
  doSleep(256);
  long tt2=millis();
  calibv = 256.0/(tt2-tt1);
}

// Estimated millis is real clock + calibrated sleep time
long estMillis() {
  return millis()+timeSleep;
}

// Delay function
void sleepCPU_delay(long sleepTime) {
  ADCSRA &= ~(1<<ADEN);  // adc off
  PRR = 0xEF; // modules off

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  int trem = doSleep(sleepTime*calibv);
  timeSleep += (sleepTime-trem);

  PRR = 0x00; //modules on
  ADCSRA |= (1<<ADEN);  // adc on
}

// internal function.  
int doSleep(long timeRem) {
  byte WDTps = 9;  // WDT Prescaler value, 9 = 8192ms

  isrcalled = 0;
  sleep_enable();
  while(timeRem > 0) {
    //work out next prescale unit to use
    while ((0x10<<WDTps) > timeRem && WDTps > 0) {
      WDTps--;
    }
    // send prescaler mask to WDT_On
    WDT_On((WDTps & 0x08 ? (1<<WDP3) : 0x00) | (WDTps & 0x07));
    isrcalled=0;
    while (isrcalled==0) {
      // turn bod off
      MCUCR |= (1<<BODS) | (1<<BODSE);
      MCUCR &= ~(1<<BODSE);  // must be done right before sleep
      sleep_cpu();  // sleep here
    }
    // calculate remaining time
    timeRem -= (0x10<<WDTps);
  }
  sleep_disable();
  return timeRem;
}

// wdt int service routine
ISR(WDT_vect) {
  WDT_Off();
  isrcalled=1;
}



When I compile I get the following error

PPR was not declared in this scope

If I declare the variable as a byte, the error goes away, but other similar errors.

I would normally assume that all variables have to be declared first, but from the comments on the web page, it seems that quite a few people have used this code and no one else has mentioned that the author did not declare them first so I assume that for them the code works fine as is.

Many thanks for any help.
Simon

14  Forum 2005-2010 (read only) / Syntax & Programs / Re: Cant get more than 128 Characters over serial port on: December 29, 2010, 12:43:57 pm
Yes, Yes, Yes. Have now managed to get this working.

Cant thank you all enough for helping me on this. The code from Zoomcat solved the problem. At first I was struggling even with that code, but then noticed that it was taking some time for the text I supplied by serial to get back to me. I wrapped all my code in an if(Serial.available()) statement and it now works. On this occasion this worked for me, but I could imagine in other situations this would cause a problem.

Any way here is the final code which works great.
Code:
// include the library code:
#include <LiquidCrystal.h>
  String ScreenName;
  String Message;
  String SerialInput;
  int MessageLength = 0;
  int MessageChr = 0;
  int StartChar;
  int EndChar;
  String MessageToPrint;
  String readString;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  Serial.begin(9600);
  Serial.println("serial test 0021");
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
}

void loop() {

  //char c;
  //Send a serial request for the screenname
  // when characters arrive over the serial port...
      
     if(Serial.available()){
     while (Serial.available()) {
        delay(1);
          if (Serial.available() >0) {
        char c = Serial.read();
        readString += c;}
        }

      if (readString.length() >0) {
      //Serial.println(readString);
        SerialInput = readString;
      readString="";
      }
      
      
      
       //Data sent starts with ScreenName padded to 20 characters long
       ScreenName = SerialInput.substring(0,14);
      
        lcd.setCursor(0,0);
        lcd.clear();
        lcd.print(ScreenName);  
        delay(2000);
      
              
        
        lcd.setCursor(16,1);
        Message = SerialInput.substring(14);
        MessageLength = Message.length();
        //lcd.autoscroll();
        for (MessageChr = 0; MessageChr <= MessageLength; MessageChr++)
        {
          //Get Start Character for SubString
          StartChar = MessageChr - 15;
          if (StartChar < 0)
          {
             StartChar = 0;
          }
          
         MessageToPrint = Message.substring(StartChar,MessageChr);    
         lcd.clear();
         lcd.setCursor(0,0);
         lcd.print(ScreenName);
         lcd.setCursor(0,1);
         lcd.println(MessageToPrint);
         delay(175);
        }
        delay(3000);
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Simons");
        lcd.setCursor(0,1);
        lcd.print("Twitter Ticker");
      
  

  // delay at the end of the full loop:
  delay(1000);
     }
}


Thanks again

Simon
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: Cant get more than 128 Characters over serial port on: December 29, 2010, 11:28:02 am
OK, here is my new code with the amendments made as per the suggestion by  Pauls, but I still only get 128 Characters through the Serial Port.

Have I implemented the suggestion correctly? If so then I still need a suggestion on how to correct this issue. Can anyone help, there must be a way to do this.

Thanks
Simon


Code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  pinMode(13,OUTPUT);
  // Print a message to the LCD.
  //lcd.print("hello, world!");
  delay(1000);
}

void loop() {
  String ScreenName;
  String Message;
  String SerialInput;
  int MessageLength = 0;
  int MessageChr = 0;
  int StartChar;
  int EndChar;
  char inData[160];
  byte index = 0;
  String MessageToPrint;
  //Send a serial request for the screenname
  // when characters arrive over the serial port...
  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(200);
      SerialInput = "";
      
    
      while (Serial.available() > 0){
          inData[index] = Serial.read();
          index++;
          inData[index] = '\0'; // Keep the string NULL terminated
        }
      SerialInput = inData;
      Serial.print(inData);
      
       //Data sent starts with ScreenName padded to 20 characters long
       ScreenName = SerialInput.substring(0,14);
        lcd.noAutoscroll();
        lcd.setCursor(0,0);
        lcd.clear();
        lcd.print(ScreenName);  
        delay(2000);
      
              
        
        lcd.setCursor(16,1);
        Message = SerialInput.substring(14);
        MessageLength = Message.length();
        //lcd.autoscroll();
        for (MessageChr = 0; MessageChr <= MessageLength; MessageChr++)
        {
          //Get Start Character for SubString
          StartChar = MessageChr - 15;
          if (StartChar < 0)
          {
             StartChar = 0;
          }
          
         MessageToPrint = Message.substring(StartChar,MessageChr);    
         lcd.clear();
         lcd.setCursor(0,0);
         lcd.print(ScreenName);
         lcd.setCursor(0,1);
         lcd.println(MessageToPrint);
         delay(175);
        }
        delay(3000);
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Simons");
        lcd.setCursor(0,1);
        lcd.print("Twitter Ticker");
      
  }

  // delay at the end of the full loop:
  delay(1000);
}
Pages: [1] 2 3