@ScruffR@nrobinson2000
So… I’m not sure if this is what you intended but this is what shows up in the Serial monitor:
822628206
822628206
822628206
822628206
822628206
822628206
822628206
822628206
It’s not reading the data right there. It’s subscribing to the pot data published by another Photon then sending it to the Arduino via tx/rx. and ground. The data will show show up in the Serial port. I’m just trying to get that data(0-1023) to be applied to the Servo.
I see. I think the problem is that the Arduino is not receiving strings properly. Try this code from an earlier post, replacing Serial2 with portOne and adding in your other stuff.
#include <SoftwareSerial.h>
// software serial #1: TX = digital pin 10, RX = digital pin 11
SoftwareSerial portOne(10, 11); #include <Servo.h>
Servo myServo; // create a servo object
// software serial #2: TX = digital pin 8, RX = digital pin 9
// on the Mega, use other pins instead, since 8 and 9 don’t work on the Mega
SoftwareSerial portTwo(8, 9);
String readString = “”;
void parseCommand(String command)
{
if (command == “foo”)
{
}
}
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// Start each software serial port
portOne.begin(9600);
myServo.attach(6);
}
void loop()
{
// By default, the last intialized port is listening.
// when you want to listen on a port, explicitly select it:
portOne.listen();
// while there is data coming in, read it
// and send to the hardware serial port:
while (portOne.available() > 0) {
delay(3);
char c = portOne.read();
readString += c; // Add the character to the string
}
readString.trim();
if (readString.length() > 0) // If a string has been read…
{
Serial.println("Received: " + readString); // Send the parsed string to Serial for debugging
parseCommand(readString); // Do something with the string…
readString = “”; // Clear the string
}
if (readString.length() > 0) // If a string has been read…
{
Serial.println("Received: " + readString); // Send the parsed string to Serial for debugging
parseCommand(readString); // Do something with the string…
readString = “”; // Clear the string int potVal = map(command.toInt(), 0, 1023, 0, 180); > myServo.write(potVal);
}
I get an error that says ‘command’ was not declared in this scope