-
Notifications
You must be signed in to change notification settings - Fork 1
Control Arduino Through Serial
Here you can use C & python for program in WisProduct, and control Arduino through Uart2
Note: uart0 used as debug, uart1 has been used as tunnel which transfer data between uart1 and tcp
If you want to use python for program, you need config it, but it will take up a lot of memory
In the WisCore-SDK:
$ cd wiswrt/15.05-rak-rc2
$ make menuconfig
* Select the options as below:
Languages --->
Python --->
<*> python
<*> python-pyserial
<*> python-pip
* Save and exit
$ cd ../../
$ make
By default Uart2 is disabled, you need enable it to control arduino - How to enable Uart2
2.1 Get IDE - download arduino IDE, then install it
Connect Table:
Arduino | WisProduct Uart2 | Silkprint |
---|---|---|
RX | UART_TXD2 | PWM2 |
TX | UART_RXD2 | PWM3 |
GND | \ | GND |
Connect Picture:
If not, pls install drivers
Board:"Arduino Leonardo ETH"
Port:"COMn (Arduino Leonardo ETH)"
Here I will control LED(D13) of arduino through WisProduct with python.
In this way, you should program both in Arduino & WisProduct.
Note: Here are Serial&Serial1, Serial is "USB COM", Serial1 is "Uart"
void setup() {
// put your setup code here, to run once:
Serial1.begin(115200); //init Uart
pinMode(13,OUTPUT); //init D13
}
void loop() {
//put your main code here, to run repeatedly:
int c = Serial1.read(); //read uart data
if(c != -1){
switch(c){
case '0':
digitalWrite(13,0); //set D13 low level
break;
case '1':
digitalWrite(13,1); //set D13 high level
break;
}
}
}
then Compile & Upload
In the Arduino IDE, there are some examples for you to reference
"File" ---> "Examples" --->
vi Arduino_led_serial_test.py
import serial
import time
s = None;
def setup():
global s;
s = serial.Serial("/dev/ttyS2",115200);
def loop():
s.write("1");
time.sleep(1);
s.write("0");
time.sleep(1);
setup();
while True:
loop();
Then save the file & execute
python Arduino_led_serial_test.py
Finally you will find the LED in Arduino blinks