Im attempting to play with sending data to my arduino and keep running into the same problem. The code on the arduino is as follows:
void setup()
{
Serial.begin(9600);
for (int i = 3; i <= 13; i++)
{
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
}
void loop()
{
if (Serial.available())
{
char ch = Serial.read();
int it = ch - '0';
digitalWrite(it, HIGH);
delay(1000);
digitalWrite(it, LOW);
}
}
This basically makes it so when you send a character over the serial monitor to the device it lights up the light connected to the specified pin for one second.
In the built in serial monitor this works fine, you send the device a number 1-9 (haven't figured out how to do 10+ yet) and the specified light turns on, just as intended. However, my goal is to write a c++ program to send data to the device using the system() command from windows.h. Before i can do that i need the command to send data to the device. I found:
echo i > COM1 //with i being the number to be sent over
Well i tried that and got a fairly interesting result half the time i would receive this message in the command line:
C:/users/XXXXX> echo 7 > COM3 //im 100% sure im using com3
Access is denied
The other half of the time i would see the data go through (The RX light would light up) but nothing would happen, the light connected to pin 7 wouldn't light up. I immedatly thought that you might need to pass the data in ASCII, but nope,
echo 55 > COM3
produced the same result. If any one knows how to send data over window command line to arduio i would really appreciate it, thanks.