RadioHead Error: invalid conversion from 'char*' to 'const uint8_t* {aka const u

hi al.

i have a sketch that's giving me problems.

I'm using a cheap 344mhz module with the RadioHead library. this all works fine when using the web editor.

however, wyen compiling the sketchwith the arduino ide on my rpi i get this errors while compiling.

/home/pi/sketchbook/libraries/RadioHead/RH_E32.cpp: In member function 'bool RH_E32::writeParameters(RH_E32::Parameters&, bool)':
/home/pi/sketchbook/libraries/RadioHead/RH_E32.cpp:78:59: error: invalid conversion from 'char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]
   size_t result = _s->write((char*)&params, sizeof(params));
                                                           ^
In file included from /usr/share/arduino/hardware/arduino/cores/arduino/Stream.h:26:0,
                 from /usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.h:28,
                 from /usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:193,
                 from /home/pi/sketchbook/libraries/RadioHead/RadioHead.h:1162,
                 from /home/pi/sketchbook/libraries/RadioHead/RHGenericDriver.h:9,
                 from /home/pi/sketchbook/libraries/RadioHead/RH_E32.h:14,
                 from /home/pi/sketchbook/libraries/RadioHead/RH_E32.cpp:6:
/usr/share/arduino/hardware/arduino/cores/arduino/Print.h:53:20: note:   initializing argument 1 of 'virtual size_t Print::write(const uint8_t*, size_t)'
     virtual size_t write(const uint8_t *buffer, size_t size);
                    ^
/home/pi/sketchbook/libraries/RadioHead/RH_E32.cpp: In member function 'bool RH_E32::getVersion()':
/home/pi/sketchbook/libraries/RadioHead/RH_E32.cpp:130:57: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'char*' [-fpermissive]
   size_t result = _s->readBytes(version, sizeof(version)); // default 1 sec timeout
                                                         ^
In file included from /usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.h:28:0,
                 from /usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:193,
                 from /home/pi/sketchbook/libraries/RadioHead/RadioHead.h:1162,
                 from /home/pi/sketchbook/libraries/RadioHead/RHGenericDriver.h:9,
                 from /home/pi/sketchbook/libraries/RadioHead/RH_E32.h:14,
                 from /home/pi/sketchbook/libraries/RadioHead/RH_E32.cpp:6:
/usr/share/arduino/hardware/arduino/cores/arduino/Stream.h:76:10: note:   initializing argument 1 of 'size_t Stream::readBytes(char*, size_t)'
   size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
          ^
/home/pi/sketchbook/libraries/RadioHead/RH_E32.cpp: In member function 'virtual bool RH_E32::available()':
/home/pi/sketchbook/libraries/RadioHead/RH_E32.cpp:208:31: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'char*' [-fpermissive]
  while (_s->readBytes(&data, 1) == 1) // Not read timeout
                               ^
In file included from /usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.h:28:0,
                 from /usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:193,
                 from /home/pi/sketchbook/libraries/RadioHead/RadioHead.h:1162,
                 from /home/pi/sketchbook/libraries/RadioHead/RHGenericDriver.h:9,
                 from /home/pi/sketchbook/libraries/RadioHead/RH_E32.h:14,
                 from /home/pi/sketchbook/libraries/RadioHead/RH_E32.cpp:6:
/usr/share/arduino/hardware/arduino/cores/arduino/Stream.h:76:10: note:   initializing argument 1 of 'size_t Stream::readBytes(char*, size_t)'
   size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
          ^

i tried to update the ide but i get the message that the newest version is installed already.

anybody an idea how to fix this? i would like to make changes in the field without internet thats why I'm trying to get this all working on my raspberry pi

You're asking a Raspberry PI question in an Arduino forum? Maybe try a rpi forum for better results..

blh64:
You're asking a Raspberry PI question in an Arduino forum? Maybe try a rpi forum for better results..

I'm asking about the error while compiling not about the pi. I have compiled enough other sketches without problems on the pi.

You could use the correct data types.
That would fix the errors.

AWOL tnx for your reply. I have no idea how and what to change since this is something in the library? I have never changed libraries and I would not know what to change.

Might you be able to pinpoint for me what I have to change?

This library works on the "online editor" but not on my rpi.

Might you be able to pinpoint for me what I have to change?

Without seeing the code?
Not a hope.

err that is true.

here it is, RH_E32.cpp

// RH_E32.cpp
//
// Copyright (C) 2017 Mike McCauley
// $Id: RH_E32.cpp,v 1.2 2017/06/24 20:36:15 mikem Exp $

#include <RH_E32.h>
#include <Stream.h>

RH_E32::RH_E32(Stream *s, uint8_t m0_pin, uint8_t m1_pin, uint8_t aux_pin)
  :
  _s(s),
  _m0_pin(m0_pin),
  _m1_pin(m1_pin),
  _aux_pin(aux_pin)
{
  // Prevent glitches at startup
  pinMode(_aux_pin, INPUT);
  digitalWrite(_m0_pin, true);
  digitalWrite(_m1_pin, true);
  pinMode(_m0_pin, OUTPUT);
  pinMode(_m1_pin, OUTPUT);
}

bool RH_E32::init()
{
  // When a message is available, Aux will go low 5 msec before the first character is output
  // So if we ever wait more than this period of time after Aux low, can conclude there will be no data
  _s->setTimeout(10);

  // Wait until the module is connected
  waitAuxHigh();

  if (!getVersion())
      return false; // Could not communicate with module or wrong type of module
  
  setMode(RHModeRx);
  clearRxBuf();

  if (!setDataRate(DataRate5kbps))
    return false;

  if (!setPower(Power21dBm))
    return false;

  //  if (!setBaudRate(BaudRate9600, Parity8N1))
  //  return false;

  if (!setFrequency(433))
    return false;
  
  return true;
}

bool RH_E32::reset()
{
  setOperatingMode(ModeSleep);
  uint8_t resetCommand[] = { RH_E32_COMMAND_RESET, RH_E32_COMMAND_RESET, RH_E32_COMMAND_RESET };
  size_t result = _s->write(resetCommand, sizeof(resetCommand));
  setOperatingMode(ModeNormal);
  return (result == sizeof(resetCommand));
}

bool RH_E32::readParameters(Parameters& params)
{
  setOperatingMode(ModeSleep);
  uint8_t readParamsCommand[] = { RH_E32_COMMAND_READ_PARAMS, RH_E32_COMMAND_READ_PARAMS, RH_E32_COMMAND_READ_PARAMS };
  _s->write(readParamsCommand, sizeof(readParamsCommand));
  size_t result = _s->readBytes((char*)&params, sizeof(params)); // default 1 sec timeout
  setOperatingMode(ModeNormal);
  return (result == sizeof(Parameters));
}

bool RH_E32::writeParameters(Parameters& params, bool save)
{
  setOperatingMode(ModeSleep);
  params.head = save ? RH_E32_COMMAND_WRITE_PARAMS_SAVE : RH_E32_COMMAND_WRITE_PARAMS_NOSAVE;
  //  printBuffer("writing now", (uint8_t*)&params, sizeof(params));
  size_t result = _s->write((char*)&params, sizeof(params));
  if (result != sizeof(params))
    return false;
  
  // Now we expect to get the same data back
  result = _s->readBytes((char*)&params, sizeof(params));
  if (result != sizeof(params))
    return false;
  //    printBuffer("additional read", (uint8_t*)&params, sizeof(params));
  // Without a little delay here, writing params often fails
  delay(20);
  
  setOperatingMode(ModeNormal);
  return result == sizeof(params);
}

void RH_E32::setOperatingMode(OperatingMode mode)
{
  waitAuxHigh();
  switch (mode)
    {
    case ModeNormal:
      digitalWrite(_m0_pin, false);
      digitalWrite(_m1_pin, false);
      break;
      
    case ModeWakeUp:
      digitalWrite(_m0_pin, true);
      digitalWrite(_m1_pin, false);
      break;
      
    case ModePowerSaving:
      digitalWrite(_m0_pin, false);
      digitalWrite(_m1_pin, true);
      break;
      
    case ModeSleep:
      digitalWrite(_m0_pin, true);
      digitalWrite(_m1_pin, true);
      break;
      
    }
  delay(10); // Takes a little while to start its response
  waitAuxHigh();
}

bool RH_E32::getVersion()
{
  setOperatingMode(ModeSleep);
  uint8_t readVersionCommand[] = { RH_E32_COMMAND_READ_VERSION, RH_E32_COMMAND_READ_VERSION, RH_E32_COMMAND_READ_VERSION };
  _s->write(readVersionCommand, sizeof(readVersionCommand));
  uint8_t version[4];
  size_t result = _s->readBytes(version, sizeof(version)); // default 1 sec timeout
  setOperatingMode(ModeNormal);
  if (result == 4)
    {
      // Successful read
      //      printBuffer("read version", version, sizeof(version));
      if (version[0] != 0xc3 || version [1] != 0x32)
 {
  // Not an E32
  return false;
 }
      else
 {
  // REVISIT: do something with it?
 }
    }
  else
    {
      // Read failed: no module? Wrong baud?
      return false;
    }
  return true;
}

void RH_E32::waitAuxHigh()
{
  // REVISIT: timeout needed?
  while (digitalRead(_aux_pin) == false)
    ;
}

void RH_E32::waitAuxLow()
{
  while (digitalRead(_aux_pin) == true)
    ;
}

// Check whether the latest received message is complete and uncorrupted
void RH_E32::validateRxBuf()
{
    if (_bufLen < RH_E32_HEADER_LEN)
 return; // Too short to be a real message
    if (_bufLen != _buf[0])
      return; // Do we have all the message?
    
    // Extract the 4 headers
    _rxHeaderTo    = _buf[1];
    _rxHeaderFrom  = _buf[2];
    _rxHeaderId    = _buf[3];
    _rxHeaderFlags = _buf[4];
    if (_promiscuous ||
 _rxHeaderTo == _thisAddress ||
 _rxHeaderTo == RH_BROADCAST_ADDRESS)
    {
 _rxGood++;
 _rxBufValid = true;
    }
}

void RH_E32::clearRxBuf()
{
    _rxBufValid = false;
    _bufLen = 0;
}

bool RH_E32::available()
{
    // Caution: long packets could be sent in several bursts
    if (!_rxBufValid)
    {
 if (_mode == RHModeTx)
  return false;

 if (!_s->available())
  return false;

 // Suck up all the characters we can
 uint8_t data;
 while (_s->readBytes(&data, 1) == 1) // Not read timeout
  {
    _buf[_bufLen++] = data;
  }
 // Now assess what we have
 if (_bufLen < RH_E32_HEADER_LEN)
  {
    //    Serial.println("Incomplete header");
    return false;
  }
 else if (_bufLen < _buf[0])
  {
    //    Serial.println("Incomplete message");
    return false;
  }
 else if (   _bufLen > _buf[0]
 || _bufLen > RH_E32_MAX_PAYLOAD_LEN)
  {
    //    Serial.println("Overrun");
    clearRxBuf();
    _rxBad++;
    return false;
  }

 // Else it a partial or complete message, test it
 // printBuffer("read success", _buf, _bufLen);
 validateRxBuf(); 
    }
    return _rxBufValid;
}

bool RH_E32::recv(uint8_t* buf, uint8_t* len)
{
    if (!available())
 return false;
    if (buf && len)
    {
 // Skip the 4 headers that are at the beginning of the rxBuf
 if (*len > _bufLen - RH_E32_HEADER_LEN)
    *len = _bufLen - RH_E32_HEADER_LEN;
 memcpy(buf, _buf + RH_E32_HEADER_LEN, *len);
    }
    clearRxBuf(); // This message accepted and cleared
    return true;
}

bool RH_E32::send(const uint8_t* data, uint8_t len)
{
  if (len > RH_E32_MAX_MESSAGE_LEN)
    return false;

  waitPacketSent(); // Make sure we dont collide with previous message

  // Set up the headers
  _buf[0] = len + RH_E32_HEADER_LEN; // Number of octets in teh whole message
  _buf[1] = _txHeaderTo;
  _buf[2] = _txHeaderFrom;
  _buf[3] = _txHeaderId;
  _buf[4] = _txHeaderFlags;

  // REVISIT: do we really have to do this? perhaps just write it after writing the header?
  memcpy(_buf+RH_E32_HEADER_LEN, data, len);
  
  _s->write(_buf, len + RH_E32_HEADER_LEN);
  setMode(RHModeTx);
  _txGood++;
  // Aux will return high when the TX buffer is empty
  
  return true;
}

uint8_t RH_E32::maxMessageLength()
{
  return RH_E32_MAX_MESSAGE_LEN;
}

bool RH_E32::waitPacketSent()
{
  if (_mode == RHModeTx)
    waitAuxHigh();
  setMode(RHModeRx);
  return true;
}

bool RH_E32::setDataRate(DataRate rate)
{
  Parameters params;
  if (!readParameters(params))
    return false;
  // The DataRate enums are the same values as the register bitmasks
  params.sped &= ~RH_E32_PARAM_SPED_DATARATE_MASK;
  params.sped |= (rate & RH_E32_PARAM_SPED_DATARATE_MASK);
  return writeParameters(params);
}

bool RH_E32::setPower(PowerLevel level)
{
  Parameters params;
  if (!readParameters(params))
    return false;
  // The DataRate enums are the same values as the register bitmasks
  params.option &= ~RH_E32_PARAM_OPTION_POWER_MASK;
  params.option |= (level & RH_E32_PARAM_OPTION_POWER_MASK);
  return writeParameters(params);
}

bool RH_E32::setBaudRate(BaudRate rate, Parity parity)
{
  Parameters params;
  if (!readParameters(params))
    return false;
  // The DataRate enums are the same values as the register bitmasks
  params.sped &= ~RH_E32_PARAM_SPED_UART_BAUD_MASK;
  params.sped |= (rate & RH_E32_PARAM_SPED_UART_BAUD_MASK);

  // Also set the parity
  params.sped &= ~RH_E32_PARAM_SPED_UART_MODE_MASK;
  params.sped |= (parity & RH_E32_PARAM_SPED_UART_MODE_MASK);
  
  return writeParameters(params);
}


bool RH_E32::setFrequency(uint16_t frequency)
{
  if (frequency < 410 || frequency > 441)
    return false;
  
  Parameters params;
  if (!readParameters(params))
    return false;
  params.chan = frequency - 410;
  return writeParameters(params);
  
}

thank you for your time

@Bringamosa, post your code that is trying to use the library.

sure can post the code trying to use the library but does that matter in any way when the sketch compiles in the online editor but not on the rpi?

home/pi/sketchbook/libraries/RadioHead/RH_E32.cpp: In member function 'bool RH_E32::writeParameters(RH_E32::Parameters&, bool)':
/home/pi/sketchbook/libraries/RadioHead/RH_E32.cpp:78:59: error: invalid conversion from 'char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]
   size_t result = _s->write((char*)&params, sizeof(params));

@gfvalvo - The library itself looks to be at fault.

I'm posting from my phone at the moment, so reading code and cross-referencing is hard.

AWOL:
@gfvalvo - The library itself looks to be at fault.

I'd still like to see what types OP's code is passing as arguments.

Bringamosa:
but does that matter in any way when the sketch compiles in the online editor but not on the rpi?

Only if you're interested in independent confirmation of the problem.

if you think it helps, here it is :stuck_out_tongue:

// libraries voor trasnmitter
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile

// ultrasoon modulle
#define echoPin 6 // Echo Pin
#define trigPin 8 // Trigger Pin
#define LEDROOD 13 // Onboard LED
#define BLINK_COUNT 2 //hoe vaak de led knipperd als tank leeg is

int maximumRange = 87; ////afstand waarop de tank leeg is //// AANPASSEN
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance

// transmitter en reciever module 
const int txSpeed = 512;
const int rxPin = 5;
const int txPin = 4;
const int pttPin = 7;
#define LEDTX 8
 
RH_ASK driver(txSpeed, rxPin, txPin, pttPin);





//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!AFSTAND AANPASSEN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


 
void setup(void) 
{
  Serial.begin(9600);
  if (!driver.init())
    Serial.println("rf driver init failed");
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(LEDROOD, OUTPUT);//Change to output my pins
  pinMode(LEDTX, OUTPUT);
  digitalWrite(LEDROOD,HIGH);//Turn on red LED  
}

void loop(void) 
{
 /* The following trigPin/echoPin cycle is used to determine the
 distance of the nearest object by bouncing soundwaves off of it. */ 
 digitalWrite(trigPin, LOW); 
 delayMicroseconds(2); 

 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10); 
 
 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);
 
 //Calculate the distance (in cm) based on the speed of sound.
 distance = duration/58.2;
 
 if (distance >= maximumRange || distance <= minimumRange)
{
 Serial.println("-1");
 digitalWrite(LEDROOD, HIGH); 
 Serial.println("leeg");
 const char *msg = "1"; //stuur message 1 naar RX
 digitalWrite(LEDTX, HIGH); //LEDTX gaat branden omdat de tank vol is
 driver.send((uint8_t *)msg, strlen(msg));
 driver.waitPacketSent();
 delay(200);
}
 
 else 
{
 /* Send the distance to the computer using Serial protocol, and
 turn LED OFF to indicate successful reading. */
 Serial.println(distance);
 Serial.println("genoeg");
 digitalWrite(LEDROOD, LOW); 
 const char *msg = "2"; //stuur message 1 naar RX
 driver.send((uint8_t *)msg, strlen(msg));
 driver.waitPacketSent();
 delay(200);
}
 
 if (distance <= 14)    /// afstand waarop de tank vol is!!!/// dit is 7cm voor de voetjes plus afstand voor leeg
{
 Serial.println("vol");
 const char *msg = "3"; //stuur message 1 naar RX
 digitalWrite(LEDTX, HIGH); //LEDTX gaat branden omdat de tank vol is
 driver.send((uint8_t *)msg, strlen(msg));
 driver.waitPacketSent();
 delay(200);

for ( int i=0; i < BLINK_COUNT; i++ )
{
 digitalWrite(LEDROOD, HIGH);
 delay(200);                  
 digitalWrite(LEDROOD, LOW);    
 delay(200);
}
}
 
 


 
  delay(1000);
  
}

Compiles for me using Arduino 1.8.5 on a Win 10 machine.

Compiles for me too on the online editor.....

But can not use that since the plugin to upload to the arduino does not work on the rpi.

So, not a code or library problem, per se. Perhaps there's a forum venue that specializes in running Arduino on less traditional platforms like rpi?

At this point it is ONLY this library giving me this error on the pi. Might be the pi, but I have a feeling it is solvable in the library code. However I'm not capable of figuring that out myself...

Engineering (like life) is all about tradeoffs and priorities. What’s more important right now, continuing to fight the development tool on the rpi platform or moving to a Windows box and getting on with your project development?

I understand your way of thinking. I am hoping to skip the trade off and having the need to prioritise by meeting someone here who has just a little bit more experience than me.

Actually I think AWOL might be onto something like he mentioned before so I am not ready to abandon ship yet :slight_smile:

Thank you for your time and willingness to help I appreciate it.

So here were go, something is up with the new ARDUINO IDE that messes this up.

I installed an older version of the ide, version 1.8.5 and this one does come the code without any problems.

Still I would love to have the library working on the newer ide.

Google searches made clear that there are libraries that can be updated "fairly simple" but I just don't know where to look.