User Tools

Site Tools


arduinohouse

This is an old revision of the document!


https://forum.arduino.cc/t/arduino-433-mhz-rf-sending-numbers-instead-of-strings/619707/4 Looking at the loop() in the ask_transmitter example

void loop() {

  const char *msg = "hello";
  driver.send((uint8_t *)msg, strlen(msg));
  driver.waitPacketSent();
  delay(200);

}

There is a send() method; you can find that in C:\Users\yourUserName\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp and the first line is important.

bool RH_ASK::send(const uint8_t* data, uint8_t len)

and 'states' that the send method expects a pointer to an uint8_t (aka byte) variable and a length.

The line can also be found (in a slightly different form) in C:\Users\yourUserName\Documents\Arduino\libraries\RadioHead\RH_ASK.h (that's the file that you include at the top of the sketch).

So if you now go back to the example code, you will see (uint8_t *)msg ; this is a so-called cast that tells the compiler to treat the char array (msg) as a byte array.

So now you know that you actually need to send bytes and not characters etc. and how that's achieved.

To send an int value, you can cast the address of the variable (the pointer) to an pointer to a byte. An int occupies a number of bytes; you can find that with the sizeof operator.

That would look like

int waterPressure = 1234; drive.send1);

Because waterPressure is not an array, you need the & in front of it to get the address of the variable

https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-json

iminaries

JavaScript has only one data type which can contain multiple values: Object. An Array is a special form of object.

(Plain) Objects have the form

{key: value, key: value, …}

Arrays have the form

[value, value, …]

Both arrays and objects expose a key → value structure. Keys in an array must be numeric, whereas any string can be used as key in objects. The key-value pairs are also called the “properties”.

Properties can be accessed either using dot notation

const value = obj.someProperty;

or bracket notation, if the property name would not be a valid JavaScript identifier name [spec], or the name is the value of a variable:

the space is not a valid character in identifier names const value = obj[“some Property”]; property name as variable const name = “some Property”; const value = obj[name];

For that reason, array elements can only be accessed using bracket notation:

const value = arr[5]; arr.5 would be a syntax error property name / index as variable const x = 5; const value = arr[x];

foo.c
/*
 * flashLED.c
 *
 *  Created on: 21-Feb-2011
 *      Author: user
 * 
 */
 
#include <avr/io.h>
#include <util/delay.h>
 
// This program will turn the LEDs on for 100ms,
// then off for 200ms, endlessly.
 
int main(void)
{
  // Set Port B pins for 3 and 4 as outputs
  // PORTB bit 3 = physical pin #2 on the ATTINY45
  // PORTB bit 4 = physical pin #3 on the ATTINY45
 
  DDRB = 0x18;  // In binary this is 0001 1000 (note that is bit 3 and 4)
  // AVR-GCC also would accept 0b00011000, by the way.
 
  // Set up a forever loop using your favorite C-style 'for' loop
  for ( ; 1==1 ; )  // loop while 1 equals 1
  {
    // Set Port B pins for 3 and 4 as HIGH (i.e. turn the LEDs on)
    PORTB = 0x18;   // If we wanted only PB4 on, it'd be PORTB=0x10
 
    // Use a function (defined in delay.h) to pause 100 milliseconds
    _delay_ms(100);
 
    // Set PORTB to be all LOWs (i.e. turn the LEDs off)
    PORTB = 0x00;
 
    // Delay for a 200ms
    _delay_ms(200);
  }
 
return 1;
}
 
1)
uint8_t*)&waterPressure, sizeof(waterPressure
arduinohouse.1684305444.txt.gz · Last modified: 2023/05/17 06:37 by admin