Skip to main content
edited title
Link

Help using uint32_t? Trying to feed arduino serial from raspberry pi. Just gives seemingly random things?Any help is very very much appreciated

added 939 characters in body
Source Link

So I don't know C so I'm just trying to get some very very basic code running on my arduino to send it commands over serial.

I'm feeding serial into buf

irsend.sendNEC(0x210704FB, 32)

this works but I need to read from buf instead of hardcoding for one code.

irsend.sendNEC(buf, 32) won't compile but irsend.sendNEC((uint32_t) buf, 32) will. It just doesn't do anything.

When I use

serial.print((uint32_t) buf, 32);

it prints just seemingly random letters?

I'm trying to just feed it a serial code with a language I know a little better. I can send the hex code over serial with python but I don't know the first thing about C. I don't understand why I can't just feed it a variable and have it read it as is. here's my code

#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) {
    //tried to set up code to show what the arduino received and tried ways to send
    //Serial.print("You entered: >");
    //Serial.print(buf);
    //Serial.println("<");
    //doesn't seem to do anything irsend.sendNEC((uint32_t) buf, 32);
    //works but only for this one button irsend.sendNEC((uint32_t) buf0x210704FB, 32);
    //want to use irsend.sendNEC(0x210704FBbuf, 32);
    delay(600);
//me trying to figure out what irsend is being fed through buf Serial.print((uint32_t) buf, 32);
    
  }
}

So I don't know C so I'm just trying to get some very very basic code running on my arduino to send it commands over serial.

I'm feeding serial into buf

irsend.sendNEC(0x210704FB, 32)

this works but I need to read from buf instead of hardcoding for one code.

irsend.sendNEC(buf, 32) won't compile but irsend.sendNEC((uint32_t) buf, 32) will. It just doesn't do anything.

When I use

serial.print((uint32_t) buf, 32);

it prints just seemingly random letters?

I'm trying to just feed it a serial code with a language I know. I can send the hex code over serial with python but I don't know the first thing about C. I don't understand why I can't just feed it a variable and have it read it as is. here's my code

#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((uint32_t) buf, 32);
    //irsend.sendNEC((uint32_t) buf, 32);
    //irsend.sendNEC(0x210704FB, 32);
    delay(600);
    Serial.print((uint32_t) buf, 32);
    
  }
}

So I don't know C so I'm just trying to get some very very basic code running on my arduino to send it commands over serial.

I'm feeding serial into buf

irsend.sendNEC(0x210704FB, 32)

this works but I need to read from buf instead of hardcoding for one code.

irsend.sendNEC(buf, 32) won't compile but irsend.sendNEC((uint32_t) buf, 32) will. It just doesn't do anything.

When I use

serial.print((uint32_t) buf, 32);

it prints just seemingly random letters?

I'm trying to just feed it a serial code with a language I know a little better. I can send the hex code over serial with python but I don't know the first thing about C. I don't understand why I can't just feed it a variable and have it read it as is. here's my code

#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) {
    //tried to set up code to show what the arduino received and tried ways to send
    //Serial.print("You entered: >");
    //Serial.print(buf);
    //Serial.println("<");
    //doesn't seem to do anything irsend.sendNEC((uint32_t) buf, 32);
    //works but only for this one button irsend.sendNEC(0x210704FB, 32);
    //want to use irsend.sendNEC(buf, 32);
    //me trying to figure out what irsend is being fed through buf Serial.print((uint32_t) buf, 32);
    
  }
}
added 939 characters in body
Source Link

here's myI'm trying to just feed it a serial code

'#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((uint32_t) buf, 32); //irsend with a language I know.sendNEC((uint32_t) buf, 32); //irsend I can send the hex code over serial with python but I don't know the first thing about C.sendNEC(0x210704FB, 32); delay(600); Serial I don't understand why I can't just feed it a variable and have it read it as is.print((uint32_t) buf, 32);

} }here's my code

#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((uint32_t) buf, 32);
    //irsend.sendNEC((uint32_t) buf, 32);
    //irsend.sendNEC(0x210704FB, 32);
    delay(600);
    Serial.print((uint32_t) buf, 32);
    
  }
}

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((uint32_t) buf, 32); //irsend.sendNEC((uint32_t) buf, 32); //irsend.sendNEC(0x210704FB, 32); delay(600); Serial.print((uint32_t) buf, 32);

} }

Also, I can't get my code to paste properly? I can get it to say 'enter code here' but when I paste it in between the two ' it just pastes the first line as code and everything else is outside?

here's my code

'#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((uint32_t) buf, 32); //irsend.sendNEC((uint32_t) buf, 32); //irsend.sendNEC(0x210704FB, 32); delay(600); Serial.print((uint32_t) buf, 32);

} }

#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((uint32_t) buf, 32); //irsend.sendNEC((uint32_t) buf, 32); //irsend.sendNEC(0x210704FB, 32); delay(600); Serial.print((uint32_t) buf, 32);

} }

Also, I can't get my code to paste properly? I can get it to say 'enter code here' but when I paste it in between the two ' it just pastes the first line as code and everything else is outside?

I'm trying to just feed it a serial code with a language I know. I can send the hex code over serial with python but I don't know the first thing about C. I don't understand why I can't just feed it a variable and have it read it as is. here's my code

#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((uint32_t) buf, 32);
    //irsend.sendNEC((uint32_t) buf, 32);
    //irsend.sendNEC(0x210704FB, 32);
    delay(600);
    Serial.print((uint32_t) buf, 32);
    
  }
}
added 939 characters in body
Source Link
Loading
added 939 characters in body
Source Link
Loading
Source Link
Loading