AnswerBun.com

How can I use IRsend with a string or convert a char from serial to uint32_t?

Arduino Asked by Johnny Derpp on December 13, 2020

I’m trying to control my arduino with a raspberry pi with python instead of C++ (which I don’t know). I’ve found code to take a string from serial and print it, but instead I’d like to use IRsend to use the code. Unfortunately I’m getting the error invalid conversion from ‘char*’ to ‘uint32_t {aka long unsigned int}’ [-fpermissive]. I know this must be an incredibly dumb question but is there a int() function for uint32_t for arduino C++? that I could set blah=uint32_t(buf) and then use my irsend.sendNEC(buf, 32)? If it’s not painfully obvious, I don’t know C++ and my python isn’t great.

#include <IRremote.h>

char buf[80];

int readline(int readch, char *buffer, int len) {
  static int pos = 0;
  int rpos;

  if (readch > 0) {
    switch (readch) {
      case 'r': // Ignore CR
        break;
      case 'n': // Return on new-line
        rpos = pos;
        pos = 0; // Reset position index ready for next time
        return rpos;
      default:
        if (pos < len-1) {
          buffer[pos++] = readch;
          buffer[pos] = 0;
        }
    }
  }
  return 0;
}


void setup() {
  Serial.begin(115200);
}

IRsend irsend;

void loop() {
  if (readline(Serial.read(), buf, 80) > 0) {
    Serial.print("You entered: >");
    Serial.print(buf);
    Serial.println("<");
    irsend.sendNEC(buf, 32);
    
  }
}

Error:

/home/pi/Desktop/sendIRfromserial2addingir/sendIRfromserial2addingir.ino: 39:27: warning: invalid conversion from 'char*' to 'uint32_t {aka long unsigned int}' [-fpermissive]
             irsend.sendNEC(buf, 32);
                     
    
                  ^

In file included from

/home/pi/Desktop/sendIRfromserial2addingir/sendIRfromserial2addingir.ino:1:0:
/home/pi/Arduino/libraries/IRremote/src/IRremote.h:444:10: note:   initializing argument 1 of 'void IRsend::sendNEC(uint32_t, uint8_t, bool)'
     void sendNEC(uint32_t data, uint8_t nbits, bool repeat = false);
          ^~~~~~~`

One Answer

Instead of

irsend.sendNEC(buf, 32);

cast it to an unsigned int32 type:

irsend.sendNEC((uint32_t) buf, 32);

Correct answer by Michel Keijzers on December 13, 2020

Add your own answers!

Related Questions

Strange Arduino Serial Behavior

1  Asked on September 25, 2021 by interrobang

     

NodeMCU ESP8266

1  Asked on September 25, 2021 by anirudh-garg

     

Arduino Due Master Programming

0  Asked on September 25, 2021 by vamshi-krishna

       

Arduino Modbus Slave Library Needed

1  Asked on September 25, 2021 by a-h-shukry

 

2xArduinos, 2xDevices, I2C setup

0  Asked on September 25, 2021 by tomasito

     

ESP8266 OTA update with different flash size settings?

1  Asked on September 25, 2021 by brick

       

Esp32: is OTA compatible with FREERTOS

1  Asked on September 25, 2021 by glamis

   

regarding ardunio error

0  Asked on September 25, 2021 by pratham-maheshwari

     

ESP12E motorshield analogWrite issue when powering DC motor

1  Asked on February 28, 2021 by ameya-savale

     

Arduino Turn Signals

2  Asked on February 22, 2021

 

Arduino Pro Micro bricked?

2  Asked on February 17, 2021 by george-sp

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir