Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: problems with extracting values from Serial communication on: February 06, 2014, 03:08:19 pm
You are much much better off processing your numbers on the fly - this is
called lexical analysis, producing the float values as you go:

Works like a charm!!!! Thanks to you all!!!
2  Products / Arduino Due / Re: DS1302 Library error with Due on: February 05, 2014, 05:46:45 pm
Thanks for the update!!

I got my DS1307 working so I'm good now..
3  Using Arduino / Programming Questions / [solved] problems with extracting values from Serial communication on: February 05, 2014, 05:44:22 pm
Hi, i'm having some difficulties extracting values from a Serial connection.
I have spent way too long looking and experimenting so now it is time to ask here smiley

What I'm trying to do is this:

Thru Serial1 on my Arduino Due is data coming in like this: 200;1962;2145;2689;48;
I need to have the 1962 and the 2145 and the 2689 and the 48 as floats.
1962 stands for 19.62 degrees. Same goes for the 2145 and the 2689. The 48 is 48% humidity.

I managed to get 4 char arrays with the seperate digits and try to use atof() to convert to float (double in this case).
Some of my char arrays work fine and the others return ovf (no idea what it stands for guess it is similar to NaN).

Anyway, the code is probably easier to interpret than my explanation smiley

Code:
void ProcessJeeNodeData() {
SerIndex = 0;
int flag = 0;

// Don't read unless something is sent to Serial1;
while (Serial1.available() > 0 && SerIndex < 22) {
flag = 0;

inChar = Serial1.read(); // Read a character

// data I receive is in this format:
//200;1962;2145;2689;48; it is 3digits which I do not use, 4 digits temperature * 100, 4 digits temperature * 100, 4 digits temerature * 100, 2 digits humidity
//0123456789012345678901  location of the different chars in the datastring
//I write the values to 4 char arrays: TempVal1[3], TempVal2[3], TempVal3[3] and RVVal1[1]

// extracting the first temperature
if (SerIndex > 3 && SerIndex < 8) {
TempVal1[SerIndex-4] = inChar;
Serial.print(SerIndex);Serial.print(" => ");Serial.print("TempVal1[");Serial.print(SerIndex-4);Serial.print("]=");Serial.println(TempVal1[SerIndex-4]);
flag = 1;
}

// extracting the second temperature
if (SerIndex > 8 && SerIndex < 13) {
TempVal2[SerIndex-9] = inChar;
Serial.print(SerIndex);Serial.print(" => ");Serial.print("TempVal2[");Serial.print(SerIndex-9);Serial.print("]");Serial.println(TempVal2[SerIndex-9]);
flag = 1;
}

// extracting the third temperature
if (SerIndex > 13 && SerIndex < 18) {
TempVal3[SerIndex-14] = inChar;
Serial.print(SerIndex);Serial.print(" => ");Serial.print("TempVal3[");Serial.print(SerIndex-14);Serial.print("]");Serial.println(TempVal3[SerIndex-14]);
flag = 1;
}

// extracting the humidity
if (SerIndex > 18 && SerIndex < 21) {
RVVal1[SerIndex-19] = inChar;
Serial.print(SerIndex);Serial.print(" => ");Serial.print("RVVal1[");Serial.print(SerIndex-19);Serial.print("]");Serial.println(RVVal1[SerIndex-19]);
flag = 1;
}

// for debugging I also print the chars I skip. Using the flag to trigger this
if (flag == 0) {
Serial.print(SerIndex);Serial.print(" => ");Serial.print("inChar = ");Serial.println(inChar);
flag = 0;
}


           SerIndex++; // Increment where to write next
}

// after receiving the data and collecting it into the char arrays I process the raw data to floats
if (SerIndex > 0) {

Temp_DS_1 = atof(TempVal1);
Temp_DS_2 = atof(TempVal2);
Temp_SHT = atof(TempVal3);
RV_SHT = atof(RVVal1);


Serial.print("Temp_DS_1 = ");Serial.print(Temp_DS_1);Serial.print(" => ");Serial.print(Temp_DS_1 / 100.0);Serial.println("deg");
Serial.print("Temp_DS_2 = ");Serial.print(Temp_DS_2);Serial.print(" => ");Serial.print(Temp_DS_2 / 100.0);Serial.println("deg");
Serial.print("Temp_SHT = ");Serial.print(Temp_SHT);Serial.print(" => ");Serial.print(Temp_SHT / 100.0);Serial.println("deg");
Serial.print("RV_SHT = ");Serial.print(RV_SHT);Serial.print(" => ");Serial.print(RV_SHT);Serial.println("%");
}

/*  the result in my serial window is:
0 => inChar = 2
1 => inChar = 0
2 => inChar = 0
3 => inChar = ;
4 => TempVal1[0]=1
5 => TempVal1[1]=9
6 => TempVal1[2]=5
7 => TempVal1[3]=6
8 => inChar = ;
9 => TempVal2[0]2
10 => TempVal2[1]1
11 => TempVal2[2]9
12 => TempVal2[3]3
13 => inChar = ;
14 => TempVal3[0]2
15 => TempVal3[1]8
16 => TempVal3[2]7
17 => TempVal3[3]8
18 => inChar = ;
19 => RVVal1[0]4
20 => RVVal1[1]6
21 => inChar = ;
Temp_DS_1 = ovf => 1956219289.60deg
Temp_DS_2 = 21932878.00 => 219328.78deg
Temp_SHT = 2878.00 => 28.78deg
RV_SHT = 46.00 => 46.00%
0 => inChar =
1 => inChar =

Temp_DS_1 = ovf => 1956219289.60deg
Temp_DS_2 = 21932878.00 => 219328.78deg
Temp_SHT = 2878.00 => 28.78deg
RV_SHT = 46.00 => 46.00%
*/
}

I hope someone can explain to my where I'm going wrong and point me into the right direction. Maybe/probably there is a better way of doing this??
4  Products / Arduino Due / Re: DS1302 Library error with Due on: January 24, 2014, 03:35:22 pm
did you get it running???

I usually use the same library with my DS1302 on a Mega2560 and/or Uno but on my Due I get no proper date/time.
No error either....

If you got your DS1302 running on your Due I would like to know how you did it!!!!
5  Using Arduino / Programming Questions / Re: some curious problems on: October 22, 2013, 12:05:52 pm
Weird, but I think I found it.

@Nick: I guess you're using arduino IDE 1.5.2!? I noticed that that version works for me while it was Arduino IDE 1.0.1 that gave me problems...

.@PaulS: thanks for making the memory usage a bit more clear to me. Maybe you can give me an example on how I could make a nice Get method to retrieve the data? Like I say in my signature, my background is more mechanical than software...
6  Using Arduino / Programming Questions / Re: some curious problems on: October 19, 2013, 06:55:12 am
Maybe, but I'm not going there. The proper way to provide code is to use the Additional Options link and attach the code to your post.

If you prefer it that way I'll add the code as attachment as well.... see original post.


Hmmm, running out of memory.. Can't imagine why.
The code used to convert between HSL and RGB and vice versa has quite some floats but those commands are commented out.
7  Using Arduino / Programming Questions / some curious problems on: October 19, 2013, 02:33:14 am
EDIT: seems to be fixed by using Arduino 1.5.2 instead of 1.0.1


Hi,

I was trying to enhance a RGB led library I wrote some time ago as a first library I made.

When using it I get some curious results.
For some reason the sketch seems to reset itself but I can't figure out why...

When I run this sketch all is well but as soon as I uncomment the Serial.println(" "); in debugMyRGBvalues():
Code:
void debugMyRGBvalues() {
//Serial.print(myLEDstrip.RedVal);Serial.print(",");
//Serial.print(myLEDstrip.GreenVal);Serial.print(",");
//Serial.print(myLEDstrip.BlueVal);
Serial.println(" ");
}

the code will run upto
Code:
else if (i==4) {
then starts over again in void setup()

Code:
void loop()
{
curMillis = millis();
if ((curMillis - prevMillis) > 1000) {

Serial.print("i=");Serial.print(i);Serial.print(" ");

if (i==0) {
myLEDstrip.SetRedLight(255);
Serial.print("Red ");
debugMyRGBvalues();
}
else if (i==1) {
myLEDstrip.SetGreenLight(255);
Serial.print("Green ");
debugMyRGBvalues();
}
else if (i==2) {
myLEDstrip.SetBlueLight(255);
Serial.print("Blue ");
debugMyRGBvalues();
}
else if (i==3) {
myLEDstrip.SetWhiteLight(255);
Serial.print("White ");
debugMyRGBvalues();
}
else if (i==4) {
myLEDstrip.LEDstripOFF();
Serial.print("Off ");
debugMyRGBvalues();
}

else if (i<10) {
myLEDstrip.SetRandomColour();
Serial.print("Random ");
debugMyRGBvalues();
}
else if (i<15) {
int RR = 111;
myLEDstrip.SetRGBColour(RR,50,200);
Serial.print("Set RGB ");
debugMyRGBvalues();
}
else if (i<20) {
//myLEDstrip.SetHSLColour(200,100,50);
Serial.print("Set HSL ");
debugMyRGBvalues();

}
else  {
i=-1;
Serial.println("");
}




i++;

prevMillis = curMillis;

}

}

Same happens if I change
Code:
int RR = 111;
to
Code:
int RR = random(255);

And If I uncomment
Code:
myLEDstrip.SetHSLColour(200,100,50);

To make a long story short: the sketch becomes very unpredictable and unreliable smiley-sad

It is probably a minor thing that causes this but I have no clue where to look...
I hope someone can shed some RGB light on this  smiley-red
8  Using Arduino / Motors, Mechanics, and Power / Re: Velleman K8056 8-channel relaycard library on: April 23, 2013, 06:07:47 am
new version is online

Added to the playground
9  Using Arduino / Motors, Mechanics, and Power / Re: Velleman K8056 8-channel relaycard library on: April 22, 2013, 08:08:51 am
Quote
The Leonardo and Micro have two serial ports, "Serial" and "Serial1". Could you add that ?
I added the old Mega1280 to the list it is similar to the 2560.

If I understand correctly, the Leonardo and the Micro have 2 serial ports:
Quote
Note that on the Micro, the Serial class refers to USB (CDC) communication; for TTL serial on pins 0 and 1, use the Serial1 class.
So actually for my purpose there is only one correct way: Serial1. The other Serial is only accessible thru USB??
COuld anyone enlighten me on the syntax to conditional compile for those 2 boards?
I guess I could do:
 
Code:
#ELIF defined(__AVR_xxxxx__)


Added support for Leonardo and Micro.
10  Using Arduino / Motors, Mechanics, and Power / Re: Velleman K8056 8-channel relaycard library on: April 21, 2013, 10:35:02 pm
Quote
Will the library compile with Uno selected ? I'm not sure about the Serial1, Serial2, Serial3.
Yes, Serial1, Serial2 and Serial3 are only available when an Arduino MEGA2560 is selected:
Code:
#if defined(__AVR_ATmega2560__)
switch (SerialAddress) {
case 0:
Serial.begin(BaudRate);
SerialID=0;
break;
case 1:
Serial1.begin(BaudRate);
SerialID=1;
break;
case 2:
Serial2.begin(BaudRate);
SerialID=2;
break;
case 3:
Serial3.begin(BaudRate);
SerialID=3;
break;
default:
Serial.begin(BaudRate);
SerialID=0;
break;
}
#else
Serial.begin(2400);
SerialID=0;
#endif
For all other boards Serial.begin is used.

Quote
Why not call the function "On", instead of Relais_ON ?
If the class would be called "Relay", it would be called with Relay.Relay_ON().
Well, that just didn't occur to me  smiley-razz I'll change that in a next version. => DONE

Quote
You could follow the digitalWrite(pin,HIGH/LOW) function, and use a parameter for On and Off: set( relay, HIGH=on/LOW=off)
Good idea... => added Set function

Quote
Most Arduino functions use "begin()", instead of "Initialize()".
hmmm, that is true. Init or initialize is something I usually use, but for standarisation begin would be more intuative. => DONE

Quote
Why did you use real 'tabs' ? I thought that the Arduino IDE uses spaces as tabs.
tabs, I love tabs smiley I use VisualMicro in VisualStudio 2010 to do both my Arduino coding as other programming languages. I'm used to use tabs.. Guilty as charged smiley


Quote
Why did you use a switch() statement in RS232Instruction().
Would this do it: Relay = RelaisNr + '0';
I never realized or tried if that would work. I'll give it a shot smiley

Quote
What is the "switch (SerialID)" doing ? Every case is the same code.
No it is not :p If SerialID is set to 3 => Serial3.write etc.. Was the easiest way I could think of to be able to use multiple Serial ports on my MEGA


I also moved the CardAddress from begin to the seperate functions because up to 255 cards could be connected.


11  Using Arduino / Motors, Mechanics, and Power / Velleman K8056 8-channel relaycard library on: April 21, 2013, 04:29:44 am
Hi,

Last evening I finalized my first real library  smiley
I wanted to control my Velleman K8056 relaycard with RS232 commands, using only 1 wire  smiley-razz

Feel free to comment me and advise me for better/cleaner programming:

http://www.reptile-addict.nl/arduino/?page_id=209

I wanted to put this on the playground but havn't got a clue on how to get it there  smiley-red
12  Using Arduino / Programming Questions / Re: list of "defined(__AVR_xxxxxx__)" on: April 19, 2013, 01:55:24 pm
Bingo!!

Thanks!!!!!!
13  Using Arduino / Programming Questions / list of "defined(__AVR_xxxxxx__)" on: April 19, 2013, 12:32:03 pm
Hi,

I wonderd if anyone could tell me which "variables/names/whatever they are called" could be used in #IF defined(......)
I already figured out that both __AVR_ATmega2560__ and __AVR_ATmega1280__ could be used.
But is there a complete list somewhere??

Hope you understand my question, hard to describe smiley-sad If I knew how to describe it easily Google would have been more helpful for me smiley
14  Using Arduino / Programming Questions / math problem on: January 20, 2013, 04:34:03 pm
Hi,

I am writing a piece of code to convert RGB colours to HSL

Can anyone explain to my why the code below gives me 2 different results?
   float _H;
   float temp;
      temp = 1/6 * (((_R - _G)/Delta) + 4);
      _H = 0.1666667 * (((_R - _G)/Delta) + 4);

somehow the 1/6 is the problem... temp always returns 0. while _H returns the correct value :s

15  Using Arduino / Project Guidance / Arduino and 24V => TPS54286???? on: December 25, 2012, 02:53:53 am
I was wondering if it would be possible to use a TPS54286 from TI to power either an Arduino micro or mini using an input, into the TPS54286 obviously, of 24v.
If I understood the datasheet correctly it creates a PWM signal , thus powering an Arduino using PWM???
Other thoughts on how to incorperate these Arduino boards into a 24v environment are also very much apriciated.

It shoudn't be so hard when you realizes what a carplug to usb converter costs nowadays. The truck versions convert 24v to 5v as well.....
Pages: [1] 2