Hi everyone,
I would like to state my speculation first: my UNO board has a hardware problem.
I have got an UNO board. Now I am learn how to act as an output source to a Processing project. I started by the simpliest example in Processing, reads like this:
On Arduino IDE side:
/*
// Wiring / Arduino Code
// Code for sensing a switch status and writing the value to the serial port.
int switchPin = 4; // Switch connected to pin 4
void setup() {
pinMode(switchPin, INPUT); // Set pin 0 as an input
Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop() {
if (digitalRead(switchPin) == HIGH) { // If switch is ON,
Serial.write(1); // send 1 to Processing
} else { // If the switch is not ON,
Serial.write(0); // send 0 to Processing
}
delay(100); // Wait 100 milliseconds
}
On Processing IDE side:
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
void setup()
{
size(200, 200);
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw()
{
if ( myPort.available() > 0) { // If data is available,
val = myPort.read(); // read it and store it in val
}
background(255); // Set background to white
if (val == 0) { // If the serial value is 0,
fill(0); // set fill to black
}
else { // If the serial value is not 0,
fill(255,0,144); // set fill to light gray
}
println(val);
rect(50, 50, 100, 100);
}
I soon realize the program doesn't work properly.
- The TX led on UNO blink very fast (I think few times per second).
- When I println on Processing, reads something like:
49
13
10
10
10
1
49
13
10
10
10
1
49
13
...blahblahblah...
(which is not 0 or 1 as per expected) - I disconnect from Processing, check Arduino serial console, when I short the input pin (no. 4 in this case) to 5V (HIGH), the console changes from 0 to 1; However, when I disconnect it, the "1" last for few more seconds.
0
0
0
0 (let pin start HIGH)
1
1
1
1
1
1(stop HIGH)
1(but still keep coming "1"s)
1
1
1
0
0
0
0
...blahblahblah...
I think I have carefully write my codes. Anyone can tell me what it should be on a GOOD Arduino board? And how should I rule out the possibilities of the hardware failure of the board? (I have tried changing wires, using different ports, different HIGH sources...)
Last but not least, I think my board is NOT a genuine Arduino board. Does anyone know if Arduino officially authorized manufacturer in China (or other countries)? Is it good to buy one outside from official website?
Thank you very much!