Skip to content

Instantly share code, notes, and snippets.

@hunandy14
Last active April 8, 2016 03:17
Show Gist options
  • Save hunandy14/0982c0845ade23b8374f to your computer and use it in GitHub Desktop.
Save hunandy14/0982c0845ade23b8374f to your computer and use it in GitHub Desktop.
RaspberryPi
#include <SoftwareSerial.h>
#include <Wire.h>
#define UartRX 2
#define UartTX 3
#define Led 13
SoftwareSerial I2CBT(UartRX ,UartTX );
void CtrlLED(char str[128]);
/*================================================*/
void setup(){
Serial.begin(9600);
I2CBT.begin(38400);
Serial.println("Welcom Uart CTRL");
I2CBT.println("Welcom Uart CTRL");
pinMode(Led, OUTPUT);
}
/*================================================*/
void loop(){
ScanI2cStr();
ScanSerialStr();
}
/*================================================*/
void ScanI2cStr(){
if(I2CBT.available()) {
int strnum=0;
char str[128]="";
memset( str, 0, strlen(str) );
while (I2CBT.available() > 0){
str[strnum++] = I2CBT.read();
delay(3);
}
Serial.print("UartReturn:");
Serial.println(str);
// I2CBT.print("I2CGet:");
// I2CBT.println(str);
}
}
void ScanSerialStr(){
if(Serial.available()) {
int strnum=0;
char str[128]="";
memset( str, 0, strlen(str) );
while (Serial.available() > 0){
str[strnum++] = Serial.read();
delay(3);
}
Serial.print("ScanSerialSend:");
Serial.println(str);
// I2CBT.print("ScanSerialSend:");
I2CBT.println(str);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment