Total noob , unable to copy and paste a code correctly !

Hi , this is my first post . Ive been looking all over the forums and found someone asking a similar question but the answer were too technical for me i guess because i cant solve my issue ... I bought an arduino due and the only thing i have done so far is make the led blink to make sure i was connected ... Thanks a lot in advance to those who will try to help me :slight_smile:

So heres my issue :

Im trying to copy and paste a code from a website :

http://garagelab.com/profiles/blogs/project-li-ion-battery-tester-discharger-with-arduino

If i select the wrong board ( Uno ) , everything works fine except i cant upload to the board ...

But when im trying to verify it i get a bunch of error ! :

Arduino: 1.6.5 (Linux), Board: "Arduino Due (Programming Port)"

sketch_jun21l:7: error: 'float time' redeclared as different kind of symbol
In file included from /home/sebastien/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/arm-none-eabi/include/stdlib.h:11:0,
from /home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Arduino.h:24,
from sketch_jun21l.ino:7:
/home/sebastien/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/arm-none-eabi/include/time.h:47:11: error: previous declaration of 'time_t time(time_t*)'
time_t _EXFUN(time, (time_t _timer));
^
sketch_jun21l.ino: In function 'void measure()':
sketch_jun21l:19: error: ISO C++ forbids incrementing a pointer of type 'time_t (
)(time_t*) {aka long int ()(long int)}' [-fpermissive]
sketch_jun21l:19: error: lvalue required as increment operand
sketch_jun21l:32: error: call of overloaded 'print(time_t (&)(time_t*))' is ambiguous
sketch_jun21l.ino:32:18: note: candidates are:
In file included from /home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Stream.h:26:0,
from /home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/HardwareSerial.h:24,
from /home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Arduino.h:183,
from sketch_jun21l.ino:7:
/home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Print.h:61:12: note: size_t Print::print(char)
size_t print(char);
^
/home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Print.h:61:12: note: no known conversion for argument 1 from 'time_t(time_t*) {aka long int(long int*)}' to 'char'
/home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Print.h:62:12: note: size_t Print::print(unsigned char, int)
size_t print(unsigned char, int = DEC);
^
/home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Print.h:62:12: note: no known conversion for argument 1 from 'time_t(time_t*) {aka long int(long int*)}' to 'unsigned char'
/home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Print.h:63:12: note: size_t Print::print(int, int)
size_t print(int, int = DEC);
^
/home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Print.h:63:12: note: no known conversion for argument 1 from 'time_t(time_t*) {aka long int(long int*)}' to 'int'
/home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Print.h:64:12: note: size_t Print::print(unsigned int, int)
size_t print(unsigned int, int = DEC);
^
/home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Print.h:64:12: note: no known conversion for argument 1 from 'time_t(time_t*) {aka long int(long int*)}' to 'unsigned int'
/home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Print.h:65:12: note: size_t Print::print(long int, int)
size_t print(long, int = DEC);
^
/home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Print.h:65:12: note: no known conversion for argument 1 from 'time_t(time_t*) {aka long int(long int*)}' to 'long int'
/home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Print.h:66:12: note: size_t Print::print(long unsigned int, int)
size_t print(unsigned long, int = DEC);
^
/home/sebastien/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Print.h:66:12: note: no known conversion for argument 1 from 'time_t(time_t*) {aka long int(long int*)}' to 'long unsigned int'
sketch_jun21l.ino: In function 'void TIMER1_OVF_vect()':
sketch_jun21l:41: error: 'TCNT1' was not declared in this scope
sketch_jun21l.ino: In function 'void setup()':
sketch_jun21l:52: error: 'TIMSK1' was not declared in this scope
sketch_jun21l:53: error: 'TCCR1A' was not declared in this scope
sketch_jun21l:54: error: 'TCNT1' was not declared in this scope
sketch_jun21l:55: error: 'TCCR1B' was not declared in this scope
'float time' redeclared as different kind of symbol

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

It compiles for me with Arduino 105r2 on Windows7 Pro.

Copy and paste the code from the IDE into code tags (</> above the editor) in a post here.
For what it's worth the code compiles for me. (Uno/ 1.5.6-r2, Windows 7) Which board have you got selected in the IDE ?

I selected : " arduino due programming port " as my board .

Im running arduino 1.6.5

// Very simple Arduino Lithium-ion battery capacity tester
// from electronicsblog.net

#define LED 13
#define resistor 6.9

float capacity=0, value,voltage,current, time=0;

void measure (void) {

value= analogRead(0);

voltage=value/1024*5.0;

current = voltage/resistor;

capacity=capacity+current/3600;

time++;

Serial.print("Voltage= ");
Serial.print(voltage);

Serial.print("V Current= ");
Serial.print(current);

Serial.print("A Capacity= ");
Serial.print(capacity);
Serial.print("Ah ");

Serial.print("Discharging time= ");
Serial.print(time);
Serial.print("s ");

Serial.print("\n");
}

boolean x=false;

ISR(TIMER1_OVF_vect) {
TCNT1=0x0BDC;
x=!x;

measure();

}

void setup() {

pinMode(LED, OUTPUT);

TIMSK1=0x01; // enabled global and timer overflow interrupt;
TCCR1A = 0x00; // normal operation page 148 (mode0);
TCNT1=0x0BDC; // set initial value to remove time error (16bit counter register)
TCCR1B = 0x04; // start timer/ set clock

Serial.begin(9600);

};

void loop () {

digitalWrite(LED, x);

};

This is what im pasting

Qc85:
This is what im pasting

That compiles for me.

Just noticed the ; on the end of the setup() and loop() functions' closing }. Those are unnecessary although presumably do no harm, not sure. They don't cause a compile error though....

It seems to be my board . When i select arduino uno as my board everything is fine but i cant upload ... But when i select arduino due problems start showing up :confused:

It seems that the libraries that come with the due define a preprocessor directive named 'time', and that's messing things up.

Rename the 'time' variable in the copy/pasted code. 'time' as a bad name for a variable, anyway. What time? Time of what?

Qc85:
I selected : " arduino due programming port " as my board .

Im running arduino 1.6.5

Does the Due have the registers that are causing the errors ? As an experiment try verifying the code with Uno as the target board. If it compiles you will know that the program itself is OK.

Hi,
If you look at the article you got the sketch from, it uses a UNO.
The program uses direct code to timers, these are UNO named timers.

TIMSK1=0x01; // enabled global and timer overflow interrupt;
TCCR1A = 0x00; // normal operation page 148 (mode0);
TCNT1=0x0BDC; // set initial value to remove time error (16bit counter register)
TCCR1B = 0x04; // start timer/ set clock

I think you will find because the Due has a different achitecture to the UNO the timers are designated differently.
That is what the errors told me when I did a compile under DUE.

Tom.... :slight_smile:

Thanks a lot for the help . At least now i know why its now working . When i bought the due board i taught i was buying the same thing as the uno but a little bit better ... I guess ill buy a uno now since most people are using this one and i mostly want to paste code for now . ( Im learning to code but i started like a week ago and got all excited and bought a bunch of stuff , so im trying to make stuff work too early obviously )

Thanks again for the help ! Really nice to see so many answers in such a short amount of time .

Sébastien