Last active
April 13, 2023 23:30
-
-
Save katsuyoshi/0ceb25bb092514b94a9ecbfafc47e03c to your computer and use it in GitHub Desktop.
LoRaモジュール評価ボード E220-900T22S(JP)-EV1の伝送レート変更。M5Atom Lite使用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <M5Unified.h> | |
#define LORA_M0_PIN 21 | |
#define LORA_M1_PIN 25 | |
#define LORA_RX_PIN 23 | |
#define LORA_TX_PIN 19 | |
#define BAUDRATE_1200 0x00 | |
#define BAUDRATE_2400 0x20 | |
#define BAUDRATE_4800 0x40 | |
#define BAUDRATE_9600 0x60 | |
#define BAUDRATE_19200 0x80 | |
#define BAUDRATE_38400 0xa0 | |
#define BAUDRATE_57600 0xc0 | |
#define BAUDRATE_115200 0xe0 | |
#define BW_125 0x00 | |
#define BW_250 0x01 | |
#define BW_500 0x02 | |
#define SF_5 0x00 | |
#define SF_6 0x04 | |
#define SF_7 0x08 | |
#define SF_8 0x0c | |
#define SF_9 0x10 | |
#define SF_10 0x14 | |
#define SF_11 0x18 | |
void setLoraMode(int mode) { | |
pinMode(LORA_M0_PIN, OUTPUT); | |
pinMode(LORA_M1_PIN, OUTPUT); | |
digitalWrite(LORA_M0_PIN, mode & 0x1 != 0); | |
digitalWrite(LORA_M1_PIN, mode & 0x2 != 0); | |
} | |
void write_register(uint8_t addr, uint8_t* params, int length) { | |
Serial.printf("write addr: %d\r\n", addr); | |
Serial.printf(">> C0 %02X %02X", addr, length); | |
Serial2.write(0xc0); | |
Serial2.write(addr); | |
Serial2.write(length); | |
for (int i = 0; i < length; i++) { | |
char ch = params[i]; | |
Serial2.write(ch); | |
Serial.printf(" %02X", ch); | |
} | |
char n = 3 + length; | |
char buf[n]; | |
char *pt = buf; | |
char c = 0; | |
Serial.printf("\r\n>>"); | |
while (c < n ){ | |
if (Serial2.available()) { | |
char ch = Serial2.read(); | |
Serial.printf(" %02X", ch); | |
*pt++ = ch; | |
c++; | |
} | |
} | |
Serial.println(""); | |
} | |
void read_register(uint8_t addr, uint8_t* params, int length) { | |
Serial.printf("read addr: %d\r\n", addr); | |
Serial.printf(">> C1 %02X %02X", addr, length); | |
Serial2.write(0xc1); | |
Serial2.write(addr); | |
Serial2.write(length); | |
char n = 3 + length; | |
char buf[n]; | |
char *pt = buf; | |
char c = 0; | |
Serial.printf("\r\n>>"); | |
while (c < n ){ | |
if (Serial2.available()) { | |
char ch = Serial2.read(); | |
Serial.printf(" %02X", ch); | |
*pt++ = ch; | |
c++; | |
} | |
} | |
Serial.println(""); | |
} | |
void setup() { | |
M5.begin(); | |
Serial.begin(115200); | |
Serial2.begin(9600, SERIAL_8N1, LORA_RX_PIN, LORA_TX_PIN); | |
setLoraMode(3); | |
delay(20000); | |
uint8_t params[10]; | |
read_register(2, params, 1); | |
params[0] = BAUDRATE_9600 | BW_125 | SF_5; | |
write_register(2, params, 1); | |
} | |
void loop() { | |
delay(10); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[env:m5stack-atom] | |
platform = espressif32 | |
board = m5stack-atom | |
framework = arduino | |
monitor_speed = 115200 | |
lib_deps = | |
m5stack/M5Unified@^0.1.4 | |
ArduinoJson@^6.21.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment