cobbled together a solution a couple years ago that should work for you to get information in from analog reads -
the problem is arduino talks over serial so a number like "3.02" gets turned into a stream of ascii bytes. sometimes they show up as 0-255, other times as an ascii character (including invisible characters that were meant to control the movement of a teletypwriter). they could also be a pair of two hex symbols.. in any form theyre not human readable.
so in the arduino sketch I added functions that send the magic begin and end serial messages to use pure data's built in serial network encoder/decoder object so it should work across pd and clones versions from the last decade or so (newest vanilla is the safe bet) .. the only thing you need to have installed either bundled or using "find externals" is [comport]
heres code for the arduino to put above the setup()
//these magic functions let us send human readable info to pure data
void fudiStart(){
Serial.write(108); //Fudi
Serial.write(105); //Fudi
Serial.write(115); //Fudi
Serial.write(116); //Fudi
Serial.write(32); //Fudi
}
void fudiEnd(){
Serial.write(59); //Fudi
Serial.write(10); //Fudi
}
I also added a delay to read and send the information because if you push information too fast (faster than your monitors refresh rate) and send that to a UI like a slider or number box pure data will slog/stop responding.
unsigned long previousMillis = 0;
const long interval = 100; //10 hz (100 milliseconds) seems pretty low, 30hz is 34
now inside the loop{}
//instead of using Delay we will put reading input thats sent to Pure Data inside a timer
//this was so receiving back to arduino from pure data will happen as fast as possible
//later we could maybe use an interrupt
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
// Gather Input and send it to pure data
int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
fudiStart();
Serial.print("A0 ");
Serial.print(sensorValue1);
fudiEnd();
fudiStart();
Serial.print("A1 ");
Serial.print(sensorValue2);
fudiEnd();
}
notice the serial.print("A0 "); - this is because its going to get filtered out in pure data, I circled the important part
the other stuff was an early attempt at sending info to the arduino which hasnt been worked out and debug stuff I used to figure out how fudi talks.
there's been other ways to do this (like by https://drymonitis.me/code/ ..
and
)
so this was just what worked for me.. here's the sketch comPortFixin.pd AnalogReadSerial2PureDataFUDI.ino