flute2k3@hotmail.com
10 W
- Joined
- Nov 26, 2019
- Messages
- 98
recently I tried on Arduino, below codes tested fine with bluetooth as well as serial direct connection, the serial port/BT connects to pin 8 (Rx) and pin 9(Tx) of Arduino pro mini in my case. notice you need to cross connect from 8 to Tx of Serial port/BT, and 9 to Rx of Serial port/BT. the real time information (24 bytes) stored in Rdata[24], and show on serial monitor, you can insert your code in dataProcess() to show on OLED, LCD, etc.
C++
#include <Arduino.h>
#include <AltSoftSerial.h>
#define LED 13
AltSoftSerial AltSerial;
const byte Sdata[] = {0xc9, 0x14, 0x02, 0x53, 0x48, 0x4f, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0x1e, 0xaa, 0x04, 0x67, 0x00, 0xf3, 0x52, 0x0d};
const size_t dataLength = 24;
const int flash_msec = 200;
byte Rdata[dataLength];
int index;
int arrIndex = 0;
unsigned long currentMillis;
void dataProcess()
{
for (int i = 0; i < 24; i++)
{
if(Rdata < 16)
{
Serial.print('0');
}
Serial.print(Rdata, HEX);
Serial.print(" ");
}
Serial.println();
}
void setup() {
// initialize serial communication at 9600 bits per second:
pinMode(LED, OUTPUT);
AltSerial.begin(9600);
Serial.begin(9600);
delay(200);
currentMillis = millis();
}
void loop()
{
if(millis()-currentMillis > flash_msec)
{
currentMillis = millis();
AltSerial.write(Sdata, dataLength);
}
if(AltSerial.available() >= dataLength){
AltSerial.readBytes(Rdata, dataLength);
dataProcess();
}
}
C++
#include <Arduino.h>
#include <AltSoftSerial.h>
#define LED 13
AltSoftSerial AltSerial;
const byte Sdata[] = {0xc9, 0x14, 0x02, 0x53, 0x48, 0x4f, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0x1e, 0xaa, 0x04, 0x67, 0x00, 0xf3, 0x52, 0x0d};
const size_t dataLength = 24;
const int flash_msec = 200;
byte Rdata[dataLength];
int index;
int arrIndex = 0;
unsigned long currentMillis;
void dataProcess()
{
for (int i = 0; i < 24; i++)
{
if(Rdata < 16)
{
Serial.print('0');
}
Serial.print(Rdata, HEX);
Serial.print(" ");
}
Serial.println();
}
void setup() {
// initialize serial communication at 9600 bits per second:
pinMode(LED, OUTPUT);
AltSerial.begin(9600);
Serial.begin(9600);
delay(200);
currentMillis = millis();
}
void loop()
{
if(millis()-currentMillis > flash_msec)
{
currentMillis = millis();
AltSerial.write(Sdata, dataLength);
}
if(AltSerial.available() >= dataLength){
AltSerial.readBytes(Rdata, dataLength);
dataProcess();
}
}