Show Posts
Pages: 1 2 3 [4] 5
46  Development / Suggestions for the Arduino Project / Re: More Arduino 1.0 issues on: November 20, 2011, 04:05:31 am
Ooh really, but why then are people like Paul Stoffregen advising me to do it like that?!

http://arduino.cc/forum/index.php/topic,78985.0.html

That actually works.

And a lot of other excellent working libraries use the same construction. So either I don't get you or something else!?!

B.t.w. I removed the conditional stuff to no avail, same errors.
47  Development / Suggestions for the Arduino Project / More Arduino 1.0 issues on: November 20, 2011, 03:41:51 am
I'm now trying to port the gaikl ArduinoEthernet libraries to 1.0 RC 2.

I'm using Pauls tip:

#if ARDUINO >= 100
  #include "Arduino.h"
#else
   #include "WProgram.h"
#endif

But I still get a lot of errors. It seems to be they changed more than just renaming WProgram.h to Arduino.h and "Renamed Ethernet Client, Server, and UDP classes to EthernetClient, EthernetServer, and EthernetUDP."

Any leads on this?!

I changed:
   #include "wiring.h"
to

#if ARDUINO >= 100
  #include "Arduino.h"
#else
   #include "wiring.h"
#endif

as discussed here:
http://code.google.com/p/arduino/issues/detail?id=682

But other header files like
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>

seem to be redundant now so I also made those conditional.

E.g. Paul can you elaborate on that?! I can't find the reason for these errors other than that Arduino.h is redeclaring stuff that is already declared using the mentioned header files.

Most of the time errors are of this form:

In file included from /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:191,
                 from /Applications/Arduino.app/Contents/Resources/Java/libraries/EthernetBonjour/EthernetBonjour.cpp:29:
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:116: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, const char*)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:115: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:117: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, char)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:116: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const char*)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:118: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:117: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, char)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:119: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, int)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:118: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:120: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:119: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, int)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:121: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long int)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:120: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:122: error: declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, long unsigned int)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/WString.h:121: error: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, long int)' here
In file included from /Applications/Arduino.app/Contents/Resources/Java/libraries/EthernetBonjour/EthernetBonjour.cpp:29:
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:195: error: declaration of C function 'uint16_t makeWord(byte, byte)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:194: error: previous declaration 'uint16_t makeWord(uint16_t)' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:205: error: declaration of C function 'long int random(long int)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stdlib.h:504: error: previous declaration 'long int random()' here
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:206: error: declaration of C function 'long int random(long int, long int)' conflicts with
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Arduino.h:205: error: previous declaration 'long int random(long int)' here

48  Development / Suggestions for the Arduino Project / Arduino Pro Mini + 1.0 RC2 + RF24 on: November 14, 2011, 03:24:42 pm
For my students I'm testing RF24 with Arduino 1.0 RC 2

I am getting strange errors:
SPI/SPI.h

Arduino.h: No such file or directory

Arduino.h is there in hardware/arduino/cores/arduino (inside Arduino app on my Mac).
So any idea on how this issue is happening and so how to solve it?! (Except by putting the Arduino.h file and all other dependent files in libraries...)
it just doesn't seem to be able to find the core files.
49  Using Arduino / Programming Questions / Re: Timer problem?! on: February 24, 2011, 08:08:49 am
It works! I think the unsigned long did was the largest problem and of course the return statement before the sei().
I optimized the source.
50  Using Arduino / Programming Questions / Re: Timer problem?! on: February 24, 2011, 06:31:56 am
Well, I'll take a look at it. Most of the code was reused from the forum, and I agree on quite a few of the comments. Hope to post solved code.
51  Using Arduino / Programming Questions / Re: Timer problem?! on: February 23, 2011, 05:21:52 pm
No problem smiley forum is picky about 9500 chars so I took out some irrelevant code (methods are there).

Code:
#include <nokia_3310_lcd.h>

// Temp/humidity display using nokia 3310 LCD display shield from nuelectronics.com
// LCD Code based on source from mr. Greenbeast.

int pin = 1; // analog pin
volatile int tempref = 0;
int tempf=0; // temperature variables
int samples[8]; // variables to make a better precision
int maxi = -100,mini = 100; // to start max/min temperature

long lastTLswitch = 0;

#define TL_MAXTMP 28.0
#define TL_MINTMP 25.0

//keypad debounce parameter
#define DEBOUNCE_MAX 15
#define DEBOUNCE_ON  10
#define DEBOUNCE_OFF 3

#define NUM_KEYS 5

#define NUM_MENU_ITEM 5

// joystick number
#define UP_KEY 3
#define LEFT_KEY 0
#define CENTER_KEY 1
#define DOWN_KEY 2
#define RIGHT_KEY 4

// Pin used by Backlight, so we can turn it on and off. Pin setup in LCD init function
#define BL_PIN 7

// Pin used by Tubelight, so we can turn it on and off. Pin setup in LCD init function
#define TL_PIN 2

// menu starting points
#define MENU_X 10 // 0-83
#define MENU_Y 0 // 0-5

// adc preset value, represent top value,incl. noise & margin,that the adc reads, when a key is pressed
// set noise & margin = 30 (0.15V@5V)
int  adc_key_val[5] ={
  30, 150, 360, 535, 760 };

// debounce counters
byte button_count[NUM_KEYS];
// button status - pressed/released
byte button_status[NUM_KEYS];
// button on flags for user program
byte button_flag[NUM_KEYS];

// menu definition
char menu_items[NUM_MENU_ITEM][12]={
  "TEMPERATURE",
  "HUMIDITY",
  "BACKLIGHT",
  "TUBELIGHT",
  "ABOUT"
};

void (*menu_funcs[NUM_MENU_ITEM])(void) = {
  temperature,
  humidity,
  backlight,
  tubelight,
  about
};

char current_menu_item;
int blflag = 1;  // Backlight initially ON
volatile int tlflag = 0;  // Backlight initially OFF
char degree = 0x7b;  // Degree symbol


Nokia_3310_lcd lcd=Nokia_3310_lcd();

int getTemp0();

void setup()
{

  Serial.begin(9600); // start serial communication
  // setup interrupt-driven keypad arrays  
  // reset button arrays
  for(byte i=0; i<NUM_KEYS; i++){
    button_count[i]=0;
    button_status[i]=0;
    button_flag[i]=0;
  }

  // Setup timer2 -- Prescaler/256
  TCCR2A &= ~((1<<WGM21) | (1<<WGM20));
  TCCR2B &= ~(1<<WGM22);
  TCCR2B = (1<<CS22)|(1<<CS21);      

  ASSR |=(0<<AS2);

  // Use normal mode  
  TCCR2A =0;    
  //Timer2 Overflow Interrupt Enable  
  TIMSK2 |= (0<<OCIE2A);
  TCNT2=0x6;  // counting starts from 6;  
  TIMSK2 = (1<<TOIE2);    

  SREG|=1<<SREG_I;

  lcd.init();
  lcd.clear();

  //menu initialization
  init_MENU();
  current_menu_item = 0;
  lastTLswitch = millis();
  Serial.println(lastTLswitch);
}

void loop() {
  byte i;
  for(i=0; i<NUM_KEYS; i++) {
    if(button_flag[i] !=0) {

      button_flag[i]=0;  // reset button flag
      switch(i){
      case UP_KEY:
        // current item to normal display
        lcd.writeString(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_NORMAL );
        current_menu_item -=1;
        if(current_menu_item <0)  current_menu_item = NUM_MENU_ITEM -1;
        // next item to highlight display
        lcd.writeString(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_HIGHLIGHT );
        break;
      case DOWN_KEY:
        // current item to normal display
        lcd.writeString(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_NORMAL );
        current_menu_item +=1;
        if(current_menu_item >(NUM_MENU_ITEM-1))  current_menu_item = 0;
        // next item to highlight display
        lcd.writeString(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_HIGHLIGHT );
        break;
      case LEFT_KEY:
        init_MENU();
        current_menu_item = 0;
        break;  
      case RIGHT_KEY:
        lcd.clear();
        (*menu_funcs[current_menu_item])();
        lcd.clear();
        init_MENU();
        current_menu_item = 0;          
        break;
      }
    }
  }
}

/* menu functions */
void init_MENU(void) {

  byte i;
  lcd.clear();
  lcd.writeString(MENU_X, MENU_Y, menu_items[0], MENU_HIGHLIGHT );

  for (i=1; i<NUM_MENU_ITEM; i++) {
    lcd.writeString(MENU_X, MENU_Y+i, menu_items[i], MENU_NORMAL);
  }
}

// waiting for center key press
void waitfor_OKkey() {
  byte i;
  byte key = 0xFF;
  while (key!= CENTER_KEY){
    for(i=0; i<NUM_KEYS; i++){
      if(button_flag[i] !=0){
        button_flag[i]=0;  // reset button flag
        if(i== CENTER_KEY) key=CENTER_KEY;
      }
    }
  }
}

// Check if joystick is moved or pressed
byte checkKeypressed() {
  byte key = 0xFF;

  for(int i=0; i<NUM_KEYS; i++){
    if(button_flag[i] !=0){
      button_flag[i]=0;  // reset button flag
      if(i== CENTER_KEY) key=CENTER_KEY;
    }
  }
  return key;
}

char numStr[8];

void formatNum( int num ) {
// Format a number to 2 decimal places
}

// Display temperature in big digits, humidity in small digits underneath
void temperature() {  
  int temp, humid;
  int tempc2;
  tempc2 = getTemp0();
  // Display non changing text, there is a slight delay while first reading is taken
  lcd.gotoXY( 62,1 );
  lcd.print( tempc2 );
  lcd.print( "C" );
  // lcd.writeString(67, 1, "C", MENU_NORMAL);
  lcd.writeString(38, 5, "OK", MENU_HIGHLIGHT );
  lcd.writeString(40, 3, "%RH", MENU_NORMAL);

  long lastUpdate = 0;  // Force update
  byte i;
  byte key = 0xFF;

  // Loop to display temperaure/humidity with check for key press to exit
  while (key!= CENTER_KEY) {
    // Update temp
    if( millis() > lastUpdate + 1000) {
      // Read temperature and humidity

      temp = (int) tempc2 * 100;
      humid = 10;

      // Display temp
      formatNum( temp );
      lcd.writeStringBig(8, 0, numStr, MENU_NORMAL);

      // Display Humidity
      formatNum( humid );
      lcd.writeString(10, 3, numStr, MENU_NORMAL);

      lastUpdate = millis();
      tempc2 = getTemp0();

      //      Serial.print("de temp is hier: ");
      //      Serial.println(tempc2);
    }
    key = checkKeypressed();

  }
}

// Display humidity in big digits, temperature in small digits underneath
void humidity() {
  int temp, humid;
  // show humidity, don't have that sensor in yet.
}

// Allow backlight to be turned on and off
void backlight() {

  lcd.writeString( 0, 1, "Toggle", MENU_NORMAL);
  lcd.writeString( 0, 2, "Backlight", MENU_NORMAL);
  if( blflag != 0 ) {
    lcd.writeString( 60, 2, "Off", MENU_HIGHLIGHT);
  }
  else {
    lcd.writeString( 60, 2, "On", MENU_HIGHLIGHT);
  }

  waitfor_OKkey();

  if( blflag != 0 ) {
    blflag=0;
    digitalWrite( BL_PIN, LOW );
  }  
  else {
    blflag = 1;
    digitalWrite( BL_PIN, HIGH );
  }
}

// Allow tubelight to be turned on and off
void tubelight() {

  lcd.writeString( 0, 1, "Toggle", MENU_NORMAL);
  lcd.writeString( 0, 2, "TL Tube", MENU_NORMAL);
  if( tlflag != 0 ) {
    lcd.writeString( 60, 2, "Off", MENU_HIGHLIGHT);
  }
  else {
    lcd.writeString( 60, 2, "On", MENU_HIGHLIGHT);
  }

  waitfor_OKkey();

  if( tlflag != 0 ) {
    tlflag=0;
    digitalWrite( TL_PIN, LOW );
  }  
  else {
    tlflag = 1;
    digitalWrite( TL_PIN, HIGH );
  }
}

// The followinging are interrupt-driven keypad reading functions
//  which includes DEBOUNCE ON/OFF mechanism, and continuous pressing detection
// Convert ADC value to key number

char get_key(unsigned int input) {
  char k;

  for (k = 0; k < NUM_KEYS; k++) {
    if (input < adc_key_val[k]) {
      return k;
    }
  }

  if (k >= NUM_KEYS)
    k = -1;     // No valid key pressed
  return k;
}

void update_adc_key() {
  // ... some code
}

int getTemp0() {
  
  int tempc = 0;
  cli();
  for(int i = 0;i<=15;i++){ // gets 8 samples of temperature
    samples[i] = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
    tempc = tempc + samples[i];
    delay(50);
  }

  tempc = tempc/16.0; // better precision
  tempf = (tempc * 9)/ 5 + 32; // converts to fahrenheit
  
  if (tempc < (TL_MAXTMP)) {
    if (tempc < TL_MINTMP) {
      Serial.println(tlflag);
      Serial.print("Vorige keer: ");
      Serial.println(lastTLswitch);
      Serial.println(millis()); // this makes the code even freeze!
      if ((tlflag == 0) && ( millis() > (lastTLswitch + 2000))) {
        Serial.println("Heater on...");
        tlflag = 1;
        digitalWrite( TL_PIN, HIGH );
        lastTLswitch = millis();
      }
    }
  } else {
    // if heater is off, leave off....
    if ((tlflag == 1) && ( millis() > (lastTLswitch + 2000))) {
      tlflag = 0;
      digitalWrite( TL_PIN, LOW );
      lastTLswitch = millis();
    }
  }

  if(tempc > maxi) {
    maxi = tempc;
  } // set max temperature
  if(tempc < mini) {
    mini = tempc;
  } // set min temperature

  return tempc;
  sei();

}

// Timer2 interrupt routine -
// 1/(160000000/256/(256-6)) = 4ms interval

ISR(TIMER2_OVF_vect) {  
  TCNT2  = 6;
  tempref = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
  update_adc_key();
}

52  Using Arduino / Programming Questions / Timer problem?! on: February 23, 2011, 04:54:43 pm
I'm having a problem with my application.

The application is as follows:
a thermostat device that switches on a heater at a certain minimum value and switches it off at an other value.

The application is quite straight forward:
- a Nokia LCD 3310
- a LM35 temperature

So far so good. I'm a programmer, so combining some examples with my own code was no problem.
What is a problem is that I don't want the heater to switch on and off too fast.

Code:
long lastTLswitch = 0;

// in the main loop:

if ((tlflag == 0) && ( millis() > (lastTLswitch + 2000))) {
  // switch on the heater
} else if (millis() > (lastTLswitch + 2000)) {
  // switch off the heater
}


The problem:
1376277 is the value in lastTLswitch even when I initialize it so it functions but with a timeout that is too long.
If I print millis() it even freezes.
I suspect that interrupt ISR(TIMER2_OVF_vect) causes this problem.

I have looked around, but I didn't find the answer yet.
53  Forum 2005-2010 (read only) / Troubleshooting / usbdev_open(): did not find any USB dev on Mac on: August 27, 2010, 01:01:36 pm
I'm trying to burn optiboot using an JTAGICE mkII programmer. On Windows I don't have arduino software installed, on Mac I get this error:

usbdev_open(): did not find any USB dev

Where can I modify the avrdude settings for Arduino so I can point it to tty.usbserial-A800ep7B instead of usb (as stated by Arduino [0018]) usbdev_open(): did not find any USB device
54  Forum 2005-2010 (read only) / Troubleshooting / Re: A strange problem with inputs on: March 09, 2010, 06:06:33 pm
Yups I agree, that is also how I teach it smiley-wink
55  Forum 2005-2010 (read only) / Troubleshooting / Re: A strange problem with inputs on: March 09, 2010, 01:41:01 pm
13 years of programming and helping numerous students doesn't seem to help either. It was my software mistake. Some small mistakes cost a lot of headache.

bluval = digitalRead(bluval);

is the problem... it should have been:
bluval = digitalRead(btnblul);
56  Forum 2005-2010 (read only) / Troubleshooting / Re: A strange problem with inputs on: March 09, 2010, 11:37:41 am
Well, maybe, but the strange thing is that it is the same on a different arduino and also that it is not button specific but arduino pin specific!
57  Forum 2005-2010 (read only) / Troubleshooting / Re: A strange problem with inputs on: March 09, 2010, 06:23:36 am
I have tested some more. Connecting the pins to

Code:
 btnred = 19;
  btnyel = 18;
  btnblu = 17;
  btngrn = 16;

gives the same problem. If I turn the cable around it turns out to be that the blue button is seen by the arduino and becomes low (as is supposed to happen).

Very strange isn't it, I can't make any sense out of it.

[update]
A duemilanove gives the same outcome.
58  Forum 2005-2010 (read only) / Troubleshooting / Re: A strange problem with inputs on: March 09, 2010, 05:12:43 am
I have added that (I had it in my code, but forgot to copy it here).
59  Forum 2005-2010 (read only) / Troubleshooting / A strange problem with inputs on: March 09, 2010, 04:45:45 am
I am connecting 4 buttons to an arduino pro

At this moment I use the analog inputs, but no matter what the same problem keeps appearing: one of the buttons will not be detected. I have used my multimeter to ensure that it functions well (it becomes low when I press it):

Below the code that I use:
Code:
int btnred, btnyel, btngrn, btnblu; // buttons
int pressed = LOW;

void setup() {
  // setting the pins
  btnred = 17;
  btnyel = 16;
  btnblu = 15;
  btngrn = 14;

  pinMode(btnred, INPUT);
  digitalWrite(btnred, HIGH);
  pinMode(btnyel, INPUT);
  digitalWrite(btnyel, HIGH);
  pinMode(btngrn, INPUT);
  digitalWrite(btngrn, HIGH);  
  pinMode(btnblu, INPUT);
  digitalWrite(btnblu, HIGH);
 
  //Serial.begin(9600);

}

void loop() {
  int redval, yelval, bluval, grnval;
  redval = digitalRead(btnred);
  yelval = digitalRead(btnyel);
  bluval = digitalRead(bluval);
  grnval = digitalRead(btngrn);
  if (redval == pressed) {
    lc.setDigit(0,3,1,false);
    //Serial.println("Yellow");
  } else {
    lc.setDigit(0,3,0,false);
  }
  if (bluval == pressed) {
    lc.setDigit(0,1,1,false);
    //Serial.println("Yellow");
  } else {
    lc.setDigit(0,1,0,false);
  }
  if (grnval == pressed) {
    lc.setDigit(0,0,1,false);
    //Serial.println("Yellow");
  } else {
    lc.setDigit(0,0,0,false);
  }
  if (yelval == pressed) {
    lc.setDigit(0,2,1,false);
    //Serial.println("Yellow");
  } else {
    lc.setDigit(0,2,0,false);
  }
  delay(200);
}

B.t.w. I also seem to get crap when I use the terminal. I have tred using other pins, etc etc, then the blue button might function but an other one will fail to report when it is pressed.
60  Forum 2005-2010 (read only) / Syntax & Programs / Re: controlling multiple output pins on: March 09, 2010, 02:04:29 pm
I think you don't use millis() correctly. it will soon become larger than 7000 and then the code doesn't react anymore.
I'm also not sure what < m < does, at least it is very unusual for programmers to use it like this (even if it would be correct but I'm not sure about that).

if (interval2 < m < interval5) should be written:

if ((interval2 < m) && (m < interval5)) {

}
Pages: 1 2 3 [4] 5