simple_slave modbus with Redboard Artemis nano

I want to connect the pressure sensor to the Artemis Nano board via i2c, and then connect the board to the PC via USB to see the sensor value in the PC Modbus-program.

So I installed the library below.

https://github.com/smarmengol/Modbus-Ma … or-Arduino

When selecting a sample code(simple_slave) and compiling, if I select the Arduino-Uno board, the compiling is successful. However, if I select the Artemis Nano, an error occurs as below.

.arduinoIDE-unsaved2024524-18368-g9n6y1.16eyt\simple_slave\simple_slave.ino:14:64: error: narrowing conversion of ‘-1’ from ‘int’ to ‘uint16_t’ {aka ‘short unsigned int’} inside { } [-Wnarrowing]

3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1 };

^

Using library Modbus-Master-Slave-for-Arduino-master in folder: C:\Users\ff\Downloads\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master (legacy)

exit status 1

Compilation error: narrowing conversion of ‘-1’ from ‘int’ to ‘uint16_t’ {aka ‘short unsigned int’} inside { } [-Wnarrowing]

How do I solve this?

I don’t necessarily have to use this library.

The important thing is to transmit the sensor value to the PC via the Modbus-RS485 protocol via USB.

in the sketch try to change : uint16_t au16data[16] to ```
int16_t au16data[16]

;-( …

If I just change that(uint16 t_-> int16_t), I get another error(as below).

I think there must be another cause since that error doesn’t occur on Uno… Please help me…

paulvha:
in the sketch try to change : uint16_t au16data[16] to ```
int16_t au16data[16]

===========================

;-( …

If I just change that(uint16 t_-> int16_t), I get another error(as below).

I think there must be another cause since that error doesn’t occur on Uno… Please help me…

===================================

Compiling sketch…

“C:\Users\ff\AppData\Local\Arduino15\packages\SparkFun\tools\arm-none-eabi-gcc\8-2018-q4-major/bin/arm-none-eabi-g++” -include “C:\Users\ff\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\2.2.1\variants\SFE_ARTEMIS_NANO/mbed/mbed_config.h” -include “C:\Users\ff\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\2.2.1/cores/arduino/sdk/ArduinoSDK.h” -iprefix “C:\Users\ff\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\2.2.1/cores/” “@C:\Users\ff\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\2.2.1\variants\SFE_ARTEMIS_NANO/mbed/.cxx-flags” -MMD -DARDUINO=10607 -DARDUINO_APOLLO3_SFE_ARTEMIS_NANO -DARDUINO_ARCH_MBED -DARDUINO_ARCH_APOLLO3 -DMBED_NO_GLOBAL_USING_DIRECTIVE -DCORDIO_ZERO_COPY_HCI “@C:\Users\ff\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\2.2.1\variants\SFE_ARTEMIS_NANO/mbed/.cxx-symbols” “-IC:\Users\ff\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\2.2.1\cores\arduino” “-IC:\Users\ff\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\2.2.1\variants\SFE_ARTEMIS_NANO” “-Ic:\Users\ff\Downloads\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master” “-IC:\Users\ff\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\2.2.1/cores/arduino” “-IC:\Users\ff\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\2.2.1/cores/arduino/mbed-bridge” “-IC:\Users\ff\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\2.2.1/cores/arduino/mbed-bridge/core-api” “-IC:\Users\ff\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\2.2.1/cores/arduino/mbed-bridge/core-api/api/deprecated” “@C:\Users\ff\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\2.2.1\variants\SFE_ARTEMIS_NANO/mbed/.includes” “C:\Users\ff\AppData\Local\Temp\arduino\sketches\950ED09F5026098B50E69C0E22BFB9A9\sketch\simple_slave.ino.cpp” -o “C:\Users\ff\AppData\Local\Temp\arduino\sketches\950ED09F5026098B50E69C0E22BFB9A9\sketch\simple_slave.ino.cpp.o”

C:\Users\ff\AppData\Local\Temp.arduinoIDE-unsaved2024524-18368-g9n6y1.16eyt\simple_slave\simple_slave.ino: In function ‘void loop()’:

C:\Users\ff\AppData\Local\Temp.arduinoIDE-unsaved2024524-18368-g9n6y1.16eyt\simple_slave\simple_slave.ino:31:15: error: invalid conversion from ‘int16_t*’ {aka ‘short int*’} to ‘uint16_t*’ {aka ‘short unsigned int*’} [-fpermissive]

slave.poll( au16data, 16 );

^~~~~~~~

In file included from C:\Users\ff\AppData\Local\Temp.arduinoIDE-unsaved2024524-18368-g9n6y1.16eyt\simple_slave\simple_slave.ino:10:

c:\Users\ff\Downloads\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master/ModbusRtu.h:198:28: note: initializing argument 1 of ‘int8_t Modbus::poll(uint16_t*, uint8_t)’

int8_t poll( uint16_t *regs, uint8_t u8size ); //!<cyclic poll for slave


Using library Modbus-Master-Slave-for-Arduino-master in folder: C:\Users\ff\Downloads\Arduino\libraries\Modbus-Master-Slave-for-Arduino-master (legacy)

exit status 1

Compilation error: invalid conversion from 'int16_t*' {aka 'short int*'} to 'uint16_t*' {aka 'short unsigned int*'} [-fpermissive]

/**

  • Modbus slave example 1:

  • The purpose of this example is to link a data array

  • from the Arduino to an external device.

  • Recommended Modbus Master: QModbus

  • http://qmodbus.sourceforge.net/

*/

#include <ModbusRtu.h>

//#include <Arduino.h>

// data array for modbus network sharing

//uint16_t au16data[16] = {

// 3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1 };

int16_t au16data[16] = {

3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1 };

/**

  • Modbus object declaration

  • u8id : node id = 0 for master, = 1…247 for slave

  • port : serial port

  • u8txenpin : 0 for RS-232 and USB-FTDI

  • or any pin number > 1 for RS-485

*/

Modbus slave(1,Serial,0); // this is slave @1 and RS-232 or USB-FTDI

void setup() {

Serial.begin( 19200 ); // baud-rate at 19200

slave.start();

}

void loop() {

slave.poll( au16data, 16 );

}

I changed the data type to int16_t in the library also. That’s fine. Thanks~!