namnamiot / rak3172_canopus Goto Github PK
View Code? Open in Web Editor NEWExamples for Canopus_RAK3172 board
Home Page: https://canopus-iot.com/
License: MIT License
Examples for Canopus_RAK3172 board
Home Page: https://canopus-iot.com/
License: MIT License
Hello sir,
I am experiencing an issue with the Canopus version 1 board. The Modbus Master example code available on GitHub is not working, and my own code that uses the frames is also not working.
this is your exemple code :
#include "Canopus_Modbus.h"
ModbusMaster node;
#include <Rak3172_Canopus.h>
#define V_RS485 PB12
#define V1
uint8_t result;
void setup()
{
pinMode(V_RS485, PWR_ON);
pinMode(PB2, OUTPUT);
Serial.begin(115200);
Serial.print("\r\n*****************RAK3172_CANOPUS*******************");
Serial_Canopus.begin(9600, SERIAL_8N1);
}
void loop()
{
//***************READ node 1**************************
node.begin(1, Serial_Canopus); //slave ID node
Serial.printf("");
Serial.printf("\r\n\n\nExample read modbus RTU for RAK3172_Canopus board");
result = node.readHoldingRegisters(0, 1);//Read 40000 to 40009
delay(10);
if (result == node.ku8MBSuccess) //Read success
{
for (uint8_t i = 0; i < 10; i ++ )
{
Serial.printf("\r\nValue 4000%d: %d", i, node.getResponseBuffer(i));
}
}
else Serial.print("Read Fail node 1"); //read fail
digitalWrite(PB2, !digitalRead(PB2)); //blink led
delay(500);
}
And this is my code, using frames (when i run this code i see tx led blinking but with a dim light):
#include <Rak3172_Canopus.h> // Include the Rak3172_Canopus library header file.
#include "Canopus_Modbus.h"
#include "Rak3172_Canopus.h"
#define V1
#define RS485_VCC PB12
byte Temp[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0a};
byte responseBuffer[50]; // Taille du tampon de réponse
float Value, Val1;
void setup() {
Serial.begin(115200);
Serial_Canopus.begin(9600, SERIAL_8N1);
pinMode(RS485_VCC, OUTPUT);
digitalWrite(RS485_VCC, PWR_ON); //On power Vrs485
//pinMode(V_SS5, PWR_ON);
}
float temp(){
// node.begin(1, Serial_Canopus); //slave ID node
RS485_Tranmit;
Serial_Canopus.write(Temp, sizeof(Temp));// Envoyer la requête au capteur
// Lire la réponse
RS485_Receive;
delay(200);
int responseLength = Serial_Canopus.available();
if (responseLength > 0) {
for (int i = 0; i < responseLength; i++) {
responseBuffer[i] = Serial_Canopus.read();
}
Value = (responseBuffer[3] << 8) | responseBuffer[4];
Value = Value/100;
Serial.print("temperature : ");
Serial.print(Value);
Serial.println(" °C");
} else {
Serial.println("Aucune réponse reçue.");
}
return Value;
}
void loop() {
Serial.println("________________________");
temp();
delay(1000);
}
notice 1 : i use a Seeed studio EC sensor (RS485, 12V) i use a externel alimentation with this sensor and the seem gnd for all the system.
notice 2 : i have also an conveter usb to RS485 for test.
Hi a Nam,
I tested your example code Rak3172 working as Modbus slave but it's doesn't work,
I am using your example and Modbus Poll working as master for reading data from Rak_v1
I don't know exactly where is the problem.
I tested some simple cases and wiring or hardware is not problem.
But when I am using this code for Rak3172 and it can't run.
Any suggest for me, Did I forget anything?
Thanks.
Hello, I like the card design, congratulations. I used your library it works fine. But I have a question. When I import high size libraries, I get "ROM overflowed" error. Have you encountered an error similar to this? When I run even the simplest example codes, it appears to be 61% full from the ROM. Thanks in advance for your answer.
Good luck.
Hi, NamNamIoT !
I’m workig with a RAK3172_CANOPUS using Arduino IDE.
It compiles ok, then uploads it to my board but fails. as shown below:
![Detect baudrate fail](https://github.com/NamNamIoT/RAK3172_CANOPUS/assets/163369668/6141faac-5e59-4990-88fa-
c59bbc56dd25)
Previously, I successfully loaded the code with STM32CubeProgrammer and switched to loading with Arduino IDE but encountered
this error.
Boards that have never been loaded with STM32CubeProgrammer will still operate normally.
Hope to receive help from you !!!
Thanks.
Hi a Nam,
I tested rak3172_canopus and using Canopus_modbus.h lib with rak_v1, when reading Modbus register when value > 255 (1 byte) i lost data.
I think problem in https://github.com/NamNamIoT/RAK3172_CANOPUS/blob/main/examples/RAK3172_ModbusRTU_Master/Canopus_Modbus.cpp
line 697, 708, 723.
Try this code below to fix it
_u16ResponseBuffer[i] = (u8ModbusADU[2 * i + 4] << 8) | u8ModbusADU[2 * i + 3];
_u16ResponseBuffer[i] = (0 << 8) | u8ModbusADU[2 * i + 3];
_u16ResponseBuffer[i] = (u8ModbusADU[2 * i + 3] << 8) | u8ModbusADU[2 * i + 4];
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.