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

How to Set RTC in ES32 using NTP server?

1  Asked on December 7, 2021 by abdul-wasey

         

Holding buttons (keyboard)

1  Asked on December 7, 2021 by amin-abbasi

 

Is it required to delete variables before going to sleep?

1  Asked on November 30, 2021 by tono-nam

   

Running Arduino with 2 outputs and 2 inputs

2  Asked on November 25, 2021

 

How to read a specific amount of data via serial?

1  Asked on November 20, 2021 by noxus-nexus

     

Can you access the EEPROM of an ATtiny with Arduino Code?

4  Asked on November 17, 2021 by isabel-alphonse

       

GPS detecting stationary?

1  Asked on November 15, 2021 by linuxferlife

     

What exactly does the return type do in a function?

2  Asked on November 13, 2021 by grant-scott

       

MPU6050 Problem with NodeMCU

1  Asked on November 5, 2021

         

AccelStepper library advanced codes!

1  Asked on September 25, 2021 by 2012user

       

Arduino I2C external 32Kb fram data organization

1  Asked on September 25, 2021 by steven-gangaram

   

Ask a Question

Get help from others!

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