Arduino Nano SBC 開始
因著 "智慧型 環境監控系統" 及 "魚菜共生 微型氣候監控系統"專題製作, 開始研究使用Arduino CPU板 及 相關IO模組, 感測器模組, 通訊模組, 運動模組.
需要體積小, 耗電小, 先從Arduino nano CPU板著手.
Arduino Nano SBC began with the "smart environment monitoring system" and relative of "fish and vegetable symbiotic microclimate monitoring system-Aquaponics System", began to study Arduino CPU boards and related IO modules, sensor modules, communication modules, motion control modules.
Need small size, low power consumption, start with the Arduino nano CPU board.
//================================================
//
// File name: nano_SW_Tx.ino
// 由Arduino nano 單板電腦 送 串列信號 至另一端電腦接收.
// Data: Nov. 14, 2017
// Version: V1.0
//
// nano SBC: D12 = Rx <--------> Tx2 (Mega-2560)
// D13 = Tx <---------> Rx2 (Mega-2560)
// or
// nano SBC: D12 = Rx <--------> D11 Tx (nano-board 2)
// D13 = Tx <---------> D10 Rx (nano-board 2)
//
/*
Arduino nano SBC Software serial test
The circuit:
* Rx is digital pin D12 (connect to Tx of other device)
* Tx is digital pin D13 (connect to Rx of other device)
Note: nano SBC : D2, D3, D4, D5, D6, D7, D8,
D9, D10, D11 ,D12 ,D13 may using as a Software serial port.
D2~D13腳位 皆可使用為軟體串列埠
This example code is in the public domain.
*/
#include <SoftwareSerial.h> // using library
int n=0; // for debug / monitor purpose
char nano_tx = " nano SBC send data via software port...... ";
// SoftwareSerial mySerial(2, 3); // define Rx, Tx pin, test OK
// SoftwareSerial mySerial(4, 5); // RX, TX , test OK
// SoftwareSerial mySerial(6, 7); // RX, TX , test OK
// SoftwareSerial mySerial(8, 9); // RX, TX, test OK
// SoftwareSerial mySerial(10, 11); // RX, TX, test OK
SoftwareSerial mySerial(12, 13); // RX, TX, test OK
void setup()
{
Serial.begin(9600);
// monitor the SBC sending info.
Serial.println(" nano SBC send the data ..... ");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop()
{
while(1) // continue sending the data
{
mySerial.print(n);
mySerial.write(" ");
mySerial.write(" nano SBC data for output: nano software Transmitter..... ");
mySerial.write(0xd);mySerial.write(0xa); // "CR"
Serial.print(n);
Serial.print(" ");
Serial.println( " nano SBC data for output: nano software Transmitter..... " );
if (n>127) // debug purpose
{n=0;}
n=n+1;
// delay(1);
}
}
//============================================
// 使用Arduino nano 單板電腦 接收
// File name: nano_SW_Rx.ino
// Use Arduino nano SBC as a receiver
// nano board-2 D10 = Rx <==> nano board-1 D13= Tx
// D11= Tx <==> nano board-1 D12= Rx
//
#include <SoftwareSerial.h> // libyary
SoftwareSerial mySerial(10, 11); // define Rx, Tx pin
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.println(" waiting for input: nano software RCVR ");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop()
{
if (mySerial.available())
{
Serial.println(mySerial.read());
delay(1);
}
}
//============================================
// 使用Arduino MEGA 2560 單板電腦 接收
// Use Arduino MEGA-2560 SBC as a receiver
//
// File name: Mega_Serial_Rx.ino
// Date: Nov. 14., 2017
// Ver.: V1.0
//The circuit:
// nano SBC Rx is digital pin D12 (connect to Tx of Mega-2560 SBC's Tx2)
// nano SBC Tx is digital pin D13 (connect to Rx of Mega-2560 SBC's Rx2)
//
void setup()
{
Serial.begin(9600); // Monitor purpose, Tx0, Rx0
Serial2.begin(9600); // data receive port, Tx2, Rx2
}
void loop()
{
// for debug purpose
Serial.println(" MEGA Port 2 , Receive 9600 n81");
while(1)
{
if (Serial1.available())
while(Serial2.available())
{
Serial.print(char (Serial2.read())); // get data
delay(1);
}
}
}