Some people probably seen my external board topic. If you haven't, I am trying to control my fan over the internet. I am trying to use a raspberry pi to connect my arduino to the internet, without the use of a bulky shield. I have the arduino connected to the pi through usb and when i use the command
echo a > /dev/ttyACM0
(a is supposed to activate fan speed 3), I can see the rx LED light up, but all that happens is pin 13, a pin that wasnt even specified in pinMode, turns off and on again. The led I have in place of the remote for speed 3 doesnt light up at all. I have also tried I2C and UART pins, with nothing happening.
I have also tried this python script:
import serial
com = serial.Serial('/dev/ttyACM0', 9600)
com.write('97') #ascii code for A as i get errors just using a normal character
And here is my arduino code:
//Initialize Relay value
boolean debug = true;
void pulseOutput(int out, int ms) {
digitalWrite(out, 1);
delay(ms);
digitalWrite(out, 0);
}
boolean relayState = false;
void setup() {
// initialize serial communication:
Serial.begin(1200);
// initialize the LED pins:
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
}
void loop() {
// See if there is a char available in serial
if (Serial.available() > 0) {
int inByte = Serial.read();
// do something different depending on the character received.
// The switch statement expects single number values for each case;
// in this exmaple, though, you're using single quotes to tell
// the controller to get the ASCII value for the character. For
// example 'a' = 97, 'b' = 98, and so forth:
switch (inByte) {
case 1:
//Fan Speed 3
if (debug) {
Serial.println("Fan speed is now at 3");
}
pulseOutput(12, 250);
break;
case 2:
//Fan Speed 2
if (debug) {
Serial.println("Fan speed is now at 2");
}
pulseOutput(11, 250);
break;
case 3:
//Fan Speed 1
if (debug) {
Serial.println("Fan speed is now at 1");
}
pulseOutput(10, 250);
break;
case 4:
//Fan Speed 0
if (debug) {
Serial.println("Fan is now off");
}
pulseOutput(9, 250);
break;
case 5:
//Toggle ceiling fan lights
if (debug) {
Serial.println("Ceiling lights are toggled");
}
pulseOutput(8, 250);
break;
case 6:
// Relay switching
if (debug) {
Serial.println("Lamps are now toggled");
}
relayState = !relayState;
if (relayState) {
digitalWrite(7, 1);
} else {
digitalWrite(7, 0);
}
break;
case 7:
// Force relay to be off
if (debug) {
Serial.println("Lamps are now off irreguardless of state");
}
digitalWrite(7, 0);
relayState = false;
break;
default:
break;
}
}
}
I have also tried a self powered usb hub and a 9v dc wall adapter, thinking that not enough power was the problem, still not working. I have also tried using integers instead of ascii values. Nope.