Show Posts
Pages: [1] 2 3 ... 6
1  Using Arduino / Programming Questions / Menu manager and LCD + Keypad on: June 27, 2014, 03:43:16 pm
Hi.

I'm looking after a menu manager library for 1602L CD + Keypad with resistors arrays on a analog pin.

Would you have something to offer for a noob.

I've seen MenuBackend but I'm not able to understand and use it.
2  Using Arduino / Programming Questions / Re: MenuBackend on: June 27, 2014, 09:36:18 am
Well, I don't know what's wrong but I've got an error importing the library <MenuBackend.h>

So I Add it as a file "MenuBachend.h" and it now works !

Add  MenuBackend.h as new file and replace  #include <MenuBackend.h>  with   #include  "MenuBackend.h"  


When I try to Add it as new Libriry it tells me :

Error in opening zip file.

But it's not a zip ! I don't understand.


Many thanks
3  Using Arduino / Programming Questions / MenuBackend on: June 27, 2014, 08:43:05 am
Hi everyone.

I'm on MenuBackend at the moment.
http://forum.arduino.cc/index.php?topic=38053.45
I've downloaded the last version :
http://www.arduino.cc/playground/uploads/Profiles/MenuBackend_1-4.zip
but I can't get it working ! It won't compile !

As I'm new, I'd like to make it working to then try to understand the code.

I've got this :
HelloMenu.pde: At global scope:
HelloMenu:69: error: variable or field 'menuUseEvent' declared void
HelloMenu:69: error: 'MenuUseEvent' was not declared in this scope

4  Using Arduino / Programming Questions / Re: Why do I get stange value from this calculation ? on: June 24, 2014, 10:43:54 am
Just to let you know I've done this to get "u_mV" :

Code:
const int R1_kOhm = 217 ;  //resistance du pont diviseur en kOhm
  const int R2_kOhm = 86 ;    //resistance du pont diviseur en kOhm 86
  long Vcc = readVcc();
  int UPONT = analogRead (A0);
  float tension_de_pont = UPONT * Vcc /1024;
  float u_mV = tension_de_pont * (R1_kOhm + R2_kOhm)/R2_kOhm;

I don't really understand the reason it didn't work and the reason it now works !
Indeed, it seems to have something to do with double and float but I got it working only making some tries, not understanding what I was doing !

5  Using Arduino / Programming Questions / Re: Why do I get stange value from this calculation ? on: June 20, 2014, 02:03:51 pm
I've already tried everything , float, double, long...


I've spend all the afternoon with this !

Everything is working except this "u_mV" I can' get the proper value !

I just don't know what else to try !
6  Using Arduino / Programming Questions / Re: Why do I get stange value from this calculation ? on: June 20, 2014, 12:47:18 pm
"long"  doesn't make any  progress.

Vcc = 5050   UPONT = 3457   u_mV = -9000   Onduleur = 0   Frigo = 0   Pompe = 0
Vcc = 5050   UPONT = 3452   u_mV = -9000   Onduleur = 0   Frigo = 0   Pompe = 0
Vcc = 5050   UPONT = 3457   u_mV = -9000   Onduleur = 0   Frigo = 0   Pompe = 0
Vcc = 5050   UPONT = 3457   u_mV = 3000   Onduleur = 0   Frigo = 0   Pompe = 0
Vcc = 5050   UPONT = 3447   u_mV = 19000   Onduleur = 0   Frigo = 0   Pompe = 0
Vcc = 5050   UPONT = 3457   u_mV = -9000   Onduleur = 1   Frigo = 1   Pompe = 1
Vcc = 5050   UPONT = 3467   u_mV = 19000   Onduleur = 0   Frigo = 0   Pompe = 0
Vcc = 5073   UPONT = 3442   u_mV = -25000   Onduleur = 1   Frigo = 1   Pompe = 1
Vcc = 5050   UPONT = 3457   u_mV = 3000   Onduleur = 0   Frigo = 0   Pompe = 0
Vcc = 5050   UPONT = 3447   u_mV = 3000   Onduleur = 0   Frigo = 0   Pompe = 0
Vcc = 5050   UPONT = 3457   u_mV = -25000   Onduleur = 0   Frigo = 0   Pompe = 0

u_mV still completely wrong with long instead of float !
7  Using Arduino / Programming Questions / Re: Why do I get stange value from this calculation ? on: June 20, 2014, 12:20:16 pm
No way, even with FLOAT, it gives me even negative value !

Here is the suspicious piece of code modified :
Code:

float calcul_tension_batterie_mV () {  //tout déclaré en int car les valeurs manipulées < 65536
const int R1_kOhm = 217 ;  //resistance du pont diviseur en kOhm
const int R2_kOhm = 100 ;    //resistance du pont diviseur en kOhm
int Vcc = readVcc();
int UPONT = analogRead (UPont);
float result = (UPONT) * Vcc /1024 * (R1_kOhm + R2_kOhm)/R2_kOhm * 1000;
  //int result = (UPONT) * Vcc * 3;
  return result; // UBat en millivolts
}

Here the complete code.
Code:
#define DEBUG

#define Led13 13
#define UPont A0 //meusure de tension au pont diviseur

#define Relai1 2
#define Pompe Relai1
#define PompeOn digitalWrite (Pompe, 0)
#define PompeOff digitalWrite (Pompe, 1)
#define EtatPompe !digitalRead (Pompe)

#define Relai2 3
#define Frigo Relai2
#define FrigoOn digitalWrite (Frigo, 0)
#define FrigoOff digitalWrite (Frigo, 1)
#define EtatFrigo !digitalRead(Pompe)

#define Relai3 4
#define Onduleur Relai3
#define OnduleurOn digitalWrite (Onduleur, 0)
#define OnduleurOff digitalWrite (Onduleur, 1)
#define EtatOnduleur !digitalRead(Onduleur)

long readVcc() {
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
  ADMUX = _BV(MUX5) | _BV(MUX0) ;
#else
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#endif 

  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring

  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH 
  uint8_t high = ADCH; // unlocks both

  long result = (high<<8) | low;

  result = 1121280L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 (Ref 1.1V = 1.095V)
  return result; // Vcc in millivolts
}

float calcul_tension_batterie_mV () {  //tout déclaré en int car les valeurs manipulées < 65536
const int R1_kOhm = 217 ;  //resistance du pont diviseur en kOhm
const int R2_kOhm = 100 ;    //resistance du pont diviseur en kOhm
int Vcc = readVcc();
int UPONT = analogRead (UPont);
float result = (UPONT) * Vcc /1024 * (R1_kOhm + R2_kOhm)/R2_kOhm * 1000;
  //int result = (UPONT) * Vcc * 3;
  return result; // UBat en millivolts
}
void blinkL13()
{
digitalWrite(Led13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(Led13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);
}
void AllumeFrigo()
{
  PompeOff;
  if (~EtatOnduleur)
  {
    OnduleurOn;
    delay(2000);
  }
  FrigoOn;
  //delay(10000);
}

void EteintFrigo()
{
  FrigoOff;
  if (~EtatPompe)
  {
    delay(500);
    OnduleurOff;
  }
}
  void AllumePompe()
  {
    if (~EtatOnduleur)
    {
      OnduleurOn;
      delay(1000);
    }
    PompeOn;
    delay(5000);
  }

  void EteintPompe()
  {
    PompeOff;
    if (~EtatFrigo)
    {
      delay(500);
      OnduleurOff;
    }
  }

  void setup() {
   #ifdef DEBUG
   Serial.begin(9600);
   #endif
    pinMode (Pompe, 1);
    pinMode (Frigo, 1);
    pinMode (Onduleur, 1);
    pinMode (UPont, 0);
    PORTD |= (1<<Onduleur) | (1<<Pompe) | (1<<Frigo); //Relais ouverts a 1 (fonctionnement des appareil à l'arrêt pour 1)
  }


void loop() {
float u_mV = calcul_tension_batterie_mV ();
  #ifdef DEBUG
int  Vcc = readVcc();
int UPONT = (analogRead (UPont)) * readVcc() /1024;

  Serial.print("Vcc = ");
  Serial.print(Vcc);
  Serial.print("   UPONT = ");
  Serial.print(UPONT);
  Serial.print("   u_mV = ");
  Serial.print(u_mV);
  Serial.print("   Onduleur = ");
  Serial.print(EtatOnduleur);
  Serial.print("   Frigo = ");
  Serial.print(EtatFrigo);
  Serial.print("   Pompe = ");
  Serial.println(EtatPompe);
  #endif
 
  blinkL13();

 
  if (u_mV > 12600)
  {
    AllumeFrigo();
  }
  if (u_mV < 12000)
  {
    EteintFrigo();
  }
  if (u_mV > 14400)
  {
    AllumePompe();
  }
  if (u_mV < 12600)
  {
    EteintPompe();
  }
}
8  Using Arduino / Programming Questions / Why do I get stange value from this calculation ? on: June 20, 2014, 11:50:42 am
Hi.

I'm trying to get this code working but I'm having strange value for "u_mV"
I guess, it's because I'm making division but even if I declare FLOAT, the result is also unwanted value.
It goes high, low, even negative for no apparent reason.

Here is the piece of code I'm suspecting to be wrong :
Code:
int calcul_tension_batterie_mV () {  //tout déclaré en int car les valeurs manipulées < 65536
const int R1_kOhm = 217 ;  //resistance du pont diviseur en kOhm
const int R2_kOhm = 100 ;    //resistance du pont diviseur en kOhm
int Vcc = readVcc();
int UPONT = analogRead (UPont);
//unsigned int result = (UPONT) * Vcc /1024 * (R1_kOhm + R2_kOhm)/R2_kOhm * 1000;
  int result = (UPONT) * Vcc * 3;
  return result; // UBat en millivolts
}


Here is the entire code :
Code:
#define DEBUG

#define Led13 13
#define UPont A0 //meusure de tension au pont diviseur

#define Relai1 7
#define Pompe Relai1
#define PompeOn digitalWrite (Pompe, 0)
#define PompeOff digitalWrite (Pompe, 1)
#define EtatPompe !digitalRead (Pompe)

#define Relai2 6
#define Frigo Relai2
#define FrigoOn digitalWrite (Frigo, 0)
#define FrigoOff digitalWrite (Frigo, 1)
#define EtatFrigo !digitalRead(Pompe)

#define Relai3 5
#define Onduleur Relai3
#define OnduleurOn digitalWrite (Onduleur, 0)
#define OnduleurOff digitalWrite (Onduleur, 1)
#define EtatOnduleur !digitalRead(Onduleur)

long readVcc() {
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
  ADMUX = _BV(MUX5) | _BV(MUX0) ;
#else
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#endif 

  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring

  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH 
  uint8_t high = ADCH; // unlocks both

  long result = (high<<8) | low;

  result = 1121280L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 (Ref 1.1V = 1.095V)
  return result; // Vcc in millivolts
}

int calcul_tension_batterie_mV () {  //tout déclaré en int car les valeurs manipulées < 65536
const int R1_kOhm = 217 ;  //resistance du pont diviseur en kOhm
const int R2_kOhm = 100 ;    //resistance du pont diviseur en kOhm
int Vcc = readVcc();
int UPONT = analogRead (UPont);
//unsigned int result = (UPONT) * Vcc /1024 * (R1_kOhm + R2_kOhm)/R2_kOhm * 1000;
  int result = (UPONT) * Vcc * 3;
  return result; // UBat en millivolts
}
void blinkL13()
{
digitalWrite(Led13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(Led13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);
}
void AllumeFrigo()
{
  PompeOff;
  if (~EtatOnduleur)
  {
    OnduleurOn;
    delay(2000);
  }
  FrigoOn;
  //delay(10000);
}

void EteintFrigo()
{
  FrigoOff;
  if (~EtatPompe)
  {
    delay(500);
    OnduleurOff;
  }
}
  void AllumePompe()
  {
    if (~EtatOnduleur)
    {
      OnduleurOn;
      delay(1000);
    }
    PompeOn;
    delay(5000);
  }

  void EteintPompe()
  {
    PompeOff;
    if (~EtatFrigo)
    {
      delay(500);
      OnduleurOff;
    }
  }

  void setup() {
   #ifdef DEBUG
   Serial.begin(9600);
   #endif
    pinMode (Pompe, 1);
    pinMode (Frigo, 1);
    pinMode (Onduleur, 1);
    pinMode (UPont, 0);
    PORTD |= (1<<Onduleur) | (1<<Pompe) | (1<<Frigo); //Relais ouverts a 1 (fonctionnement des appareil à l'arrêt pour 1)
  }


void loop() {
long u_mV = calcul_tension_batterie_mV ();
  #ifdef DEBUG
int  Vcc = readVcc();
int UPONT = (analogRead (UPont)) * readVcc() /1024;

  Serial.print("Vcc = ");
  Serial.print(Vcc);
  Serial.print("   UPONT = ");
  Serial.print(UPONT);
  Serial.print("   u_mV = ");
  Serial.print(u_mV);
  Serial.print("   Onduleur = ");
  Serial.print(EtatOnduleur);
  Serial.print("   Frigo = ");
  Serial.print(EtatFrigo);
  Serial.print("   Pompe = ");
  Serial.println(EtatPompe);
  #endif
 
  blinkL13();

 
  if (u_mV > 12600)
  {
    AllumeFrigo();
  }
  if (u_mV < 12000)
  {
    EteintFrigo();
  }
  if (u_mV > 14400)
  {
    AllumePompe();
  }
  if (u_mV < 12600)
  {
    EteintPompe();
  }
}
9  Using Arduino / Microcontrollers / Re: External Interrupt vs PinChangeInterrupt on: June 17, 2014, 10:54:37 am
So with this code :
Code:
EIMSK |= (1<<INT0)
PCMSK2 &= ~(1<<PCINT18)

I've got only 1 interrupt and I know the interrupt comes from pin 18 immediately.

Thanks, I got it a little bit more clear now.
10  Using Arduino / Microcontrollers / Re: External Interrupt vs PinChangeInterrupt on: June 17, 2014, 10:10:12 am
Whathapen if :

EIMSK |= (1<<INT0) | (1<<INT1)
PCMSK2 &= ~(1<<PCINT18)
PCMSK2 &= ~(1<<PCINT19)

Are int0 (pin18) and int1 (pin19) enable or not ?

Yes, you'll get two interrupts from the same signal.


2 interrupt even if INT0 is enable and PCINT18 is disable ? What a mess to deal with ! No way I'll be able to make a clean and working code once this way !
uC are really tricky !
11  Using Arduino / Microcontrollers / Re: External Interrupt vs PinChangeInterrupt on: June 17, 2014, 09:26:00 am
Quote
Quote
But they are also configured with EICRA and EIMSK register ! wich is very strange and confusing!
Strange? You need some way to configure it.
int0 is enabled with INT0 of EIMSK register
int1 is enabled with INT1 of EIMSK register
like this
EIMSK |= (1<<INT0) | (1<<INT1)

But int0 and int1 are also pin 18 and 19. And these pin can also be enable/disable with the register PCMSK2, like this :
PCMSK2 |= (1<<PCINT18) | (1<<PCINT19)

Whathapen if :

EIMSK |= (1<<INT0) | (1<<INT1)
PCMSK2 &= ~(1<<PCINT18)
PCMSK2 &= ~(1<<PCINT19)

Are int0 (pin18) and int1 (pin19) enable or not ?

That's what I meant

12  Using Arduino / Microcontrollers / Re: External Interrupt vs PinChangeInterrupt on: June 16, 2014, 02:48:47 pm
What difference between  INT0/INT1  and  PCINT [23:0] when

INT0  is  PCINT 18
and
INT1  is  PCINT 19

PCINT 18 and  PCINT 19  are included in  PCINT [23:0]  !

PCINT 19 and PCINT 18 are configured with the same register as all others PCINT  [23:0] pin !

But they are also configured with EICRA and EIMSK register ! wich is very strange and confusing!

If an interrupt occurs on pin PB7 wich is also PCINT 7 , PCIF0 in PCIFR register is set to 1.
So I know an interrupt has occurred on one of the goup PB7:PB0 pin. But How do I know exactly on what pin it has occured ?

Any explanation ? These interrupt with all these register are very confusing to me
13  Using Arduino / Microcontrollers / External Interrupt vs PinChangeInterrupt on: June 16, 2014, 06:00:50 am
Hi

I'm studying the AVR and I can't understand what is the difference between External Interrupt and PinChangeInterrupt

I can understand what is a PinChangeInterrupt.

But, so, what is an External Interrupt if not a PinChangeInterrupt ?
14  Using Arduino / Installation & Troubleshooting / Re: Is there no internal Vref on Pro Mini Atmega 328p ? on: June 13, 2014, 09:59:24 am
I think I see.
On this 32pin package they give us access to 2 more channel of the ADC, so we have A0:A3 (PC0:PC3) (I guess they can do analog/digitalWrite as analog/digitalRead with Pull_Up resistor) and also ADC7:6 that can do only ADC readings.
So, they're using only 6/8 channel of the ADC. And not 8/8 as you mean ?

Concerning AVcc, that's the pin that give the energy to the ADC to be able to work. It's not internaly wired as I thought.

I was mistaken with AVcc and AREF !

AREF can be either externally fed  from 0 to Vcc or better AVcc, or internaly connected to internal refernce 1.1V or AVcc.

Thanks very much for helping and learning describing all the uC little trick !
15  Using Arduino / Installation & Troubleshooting / Re: Is there no internal Vref on Pro Mini Atmega 328p ? on: June 12, 2014, 05:11:57 pm
Quote
The 32-pin TQFP and MLF packages have A6 and A7 pins
Do you mean ADC6 and ADC7 on pin 19 an 22 ?
What are these extra pin for ?

Quote
Note that PC6..4 use digital supply voltage, VCC.
You mean Vcc instead of AVcc.
I need to dig in more the datasheet indeed !
What area in the datasheet I could find explanation concerning this ?
Till now I though the uC had only 1 A/D converter !
Pages: [1] 2 3 ... 6