I want to use StampPlot software connected with Arduino,
Previously I use stampplot with pic microcontroller, with picbasicpro language,
and for controlling a dc motor, i use a slider object in Stampplot to retrieve pwm data for pic,
and I just use the command in picbasicpro: hserout ["! read obj1"], followed by hserin [dec sliderdata], then the value of sliderdata have already in a decimal data, between 0 to 255.
But I do not know, how to get data in decimal using Serial read(). Is there a dec modifier in Arduino as a dec modifier in hserin in picbasicpro, or do I have to use another command? Note: the data from Stampplot is in ASCII form, for example, for object slider data = 45, the data sent is: 52 53 124 81 124 13 and so on, the data for 128 is 49 50 56 124 81 124 13 and so on. Thanks for advance.
for object slider data = 45, the data sent is: 52 53 124 81 124 13 and so on.
That's '4', '5', '|', 'Q', '|', '' and so on.
the data for 128 is 49 50 56 124 81 124 13 and so on.
That's '1', '2', '8', '|', 'Q', '|', '' and so on.
What is causing the '|', 'Q', '|', '', and so on to be added to the data, and what does "and so on" mean?
On the Arduino, if you want to convert the serial data to numbers, you need to read in all the serial data sent, or the portion from some start-of-packet marker to some end-of-packet marker, and store it in an array of characters. You'll need to keep the array NULL terminated. Then, you can use the atoi() function to convert the string to a number.
Search the forum for "started && ended" for an example of how to read marker-delimited packets and process them.
Thank you very much Paul, yes, you're right
I've learned about the “started && ended”, and atoi() function.
now I was able to successfully get a pwm data, even though the program that I make very inefficient, but I learned a lot and I like things about how Arduino retrieve data
Below is my program to generate a pwm data from Slider object in Stampplot to Arduino.I will be happy if there is any suggestion for my program. :-?
int pwmpin=11;
char val[7];
char b[7];
int a=0;
int d=0;
boolean c=true;
void setup()
{
pinMode(pwmpin,OUTPUT);
Serial.begin(9600);
Serial.println("!o Clear");
Serial.println("!PPER 0,0");
Serial.println("!o oVSlider.Obj1=30.,80.,10.,40.,0,255,0");
}
void loop()
{
Serial.println("!READ obj1");
Serial.println("!BSND 10");
if (Serial.available()>6)
{
d=a;
val[0]=Serial.read();
for (int i=1;i<7;i++)
{
val[i]=Serial.read();
if ((val[i]>='0')&&(val[i]<='9'))
{
b[i-1]=val[i];
b[i]='\0';
}
}
a=atoi(b);
c=true;
if((val[0]==char(13))&&(val[1]>='0')&&(val[1]<='9')&&(val[2]!=char(124))&&(val[4]==char(124)))
{c=false;}
if((val[0]==char(10))&&(val[1]>='0')&&(val[1]<='9')&&(val[3]==char(124)))
{c=false;}
if((val[0]==char(124))&&(val[1]>='0')&&(val[1]<='9')&&(val[2]==char(124)))
{c=false;}
if(c){a=d;}
Serial.print("n=");
Serial.println(a);
analogWrite(pwmpin,a);
}
}