Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

RF Transmission with Aduino and Raspberry Pi

Status
Not open for further replies.

ibwev

Member
I am trying to send a string via 433 MHz transmitter (DigiKey 1597-1223-ND) attached to a Pro-Micro 5V (https://www.sparkfun.com/products/12640) to a receiver attached to Raspberry Pi 3.
TransmitterAduinoSchematicPic.jpg ReceiverRPiSchematicPic.jpgwiringPiPins.jpg
I am using the RadioHead Library to send the transmission from the Pro-Micro to the transmitter found from this tutorial https://randomnerdtutorials.com/rf-433mhz-transmitter-receiver-module-with-arduino/.

Code:
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile

RH_ASK driver;

void setup()
{
    Serial.begin(9600);   // Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{
    const char *msg = "Hello World!";
    driver.send((uint8_t *)msg, strlen(msg));
    driver.waitPacketSent();
    delay(1000);
}

I am using WiringPi and 433Utils to receive the transmission from the receiver to Raspberry Pi 3 using this tutorial https://www.princetronics.com/how-to-read-433-mhz-codes-w-raspberry-pi-433-mhz-receiver/.

Code:
/*
  RFSniffer

  Usage: ./RFSniffer [<pulseLength>]
  [] = optional

  Hacked from http://code.google.com/p/rc-switch/
  by @justy to provide a handy RF code sniffer
*/

#include "../rc-switch/RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>
     
     
RCSwitch mySwitch;



int main(int argc, char *argv[]) {
 
     // This pin is not the first pin on the RPi GPIO header!
     // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/
     // for more information.
     int PIN = 2;
     
     if(wiringPiSetup() == -1) {
       printf("wiringPiSetup failed, exiting...");
       return 0;
     }

     int pulseLength = 0;
     if (argv[1] != NULL) pulseLength = atoi(argv[1]);

     mySwitch = RCSwitch();
     if (pulseLength != 0) mySwitch.setPulseLength(pulseLength);
     mySwitch.enableReceive(PIN);  // Receiver on interrupt 0 => that is pin #2
     
   
     while(1) {
 
      if (mySwitch.available()) {
   
        int value = mySwitch.getReceivedValue();
   
        if (value == 0) {
          printf("Unknown encoding\n");
        } else {    
   
          printf("Received %i\n", mySwitch.getReceivedValue() );
        }
   
        mySwitch.resetAvailable();
   
      }
     
 
  }

  exit(0);


}

I think the sniffer code is working but the Raspberry Pi does not appear to be receiving anything even when I place the receiver and transmitter right next to each other. The Putty console looks like this once the code is running.

RFSnifferResult.jpg


Please help me understand why the Putty console of the Raspberry Pi is not displaying the transmission.
 
My first step in fault finding would be connect the serial output of the pro micro to the pin on the the Pi that you are using as an input pin. (First check that the signal levels are the same. I.E both 3.3 volts or both 5 volts. If not make a level converter.) This will eliminate the 433 Mhz transmitter and receiver. Thanks for providing full details of your problem. Also from your wiring diagrams the data from the 433 Mhz receiver is connected to GPIO 17 which is probably correct for the RF sniffer program but I think Putty is expecting the input to be from the serial RX pin.

Les.
 
First check that the signal levels are the same. I.E both 3.3 volts or both 5 volts.
How do I check that the signal levels are the same?

I removed the receiver and set the Raspberry Pi pin high in which I had the receiver connected and got 3.3 volts. Does this mean that the voltage input at any of the pins of the Raspberry Pi should not exceed 3.3 volts?

What do the voltage readings of the Pro-Micro in the below picture indicate?

TransmitterAduinoSchematicPicVolt.jpg
 
You should always read the data sheets on products to find out what the I/O signal levels are. I found this data by googling "pro micro" It suggests that it's I/O signal level is 3.3 volts. I THINK this is the same as the Raspberry Pi but you need to confirm it.

Les.
 
According to https://www.raspberrypi.org/documentation/hardware/raspberrypi/gpio/README.md , connection of a GPIO to a voltage higher than 3.3V will likely destroy the GPIO block within the SoC. Since I am using the 5V Pro Micro https://www.sparkfun.com/products/12640 , I am sure it is not safe for me to directly connect the TX pin of Pro Micro to Raspberry Pi. I would like to use a voltage divider https://randomnerdtutorials.com/how-to-level-shift-5v-to-3-3v/ to safely connect the TX pin of Pro Micro to GPIO pin of Raspberry Pi but I am getting 0.0 volts from GND to TX of Pro Micro. Does this mean that the Pro Micro is not sending a signal to the TX pin?
 
As you say you must not connect a 5 volt sugnal to a 3.3 volt signal. If I am interpreting the schematics correctlly (And I have found the correct version of the schematics) Then I think you are using the wrong I/O pins on both the pro micro and the Pi The documentation on the "hello world" program shows it using port PB4 but you have it connected to port PB3. On the Pi the documentation says it uses GPIO2 You seem to have the receiver connected to GPIO27. I have tried the code on an Arduino uno and a burst of data comes out of port PB4 about every second (Which agrees with my very limited understanding ov "C" proramming.) I have not verified that the data is correct as I have only looked at it on an oscilloscope. If you don't have a scope then you can just see a reading other than zero about every second on a multimeter.

EDIT. I have tried the rfsniffer on a Raspberry Pi (Version 2) and your drawing is correct with the receiver output connected to GPIO27 I powered the receiver from 3.3 volts rather than 5 volts so the output signal is 3.3 volts. I used a 433 MHZ keyfob for testing

Les.
 
Last edited:
Les, I really appreciate your patience, help, and time spent with this thread.

The documentation on the "hello world" program shows it using port PB4
Please help me find/understand where the documentation states using PB4. I don't see documentation on https://randomnerdtutorials.com/rf-433mhz-transmitter-receiver-module-with-arduino/. However, I know it uses the RH_ASK.h library https://www.airspayce.com/mikem/arduino/RadioHead/RH__ASK_8h_source.html. In this documentation it states to use pin 12 of the Arduino Uno for transmissions. Pin 12 of Arduino Uno is named (SP1)MISO **broken link removed**. I ASSuMEd :eek: , probably erroneously, that this meant to use the MISO pin (pin 14 https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/ProMicro16MHzv1.pdf) of the Pro Micro.

you can just see a reading other than zero about every second on a multimeter.
I have used my multimeter and the only pin on the ProMicro that receives a change in voltage from ground to the respective pin is pin 10. Pin10's change in voltage appears to be random. On pin 8, I am receiving a reading of 0.0 volts. Is it reasonable to assume that I do not have the output pin configured correctly?
 
On the ATmega328P pin 18 is PB4 (Port B bit 4 This is pin 12 on the Uno board) This pin is also the MISO signal when programming the chip normally. (As opposed to using the bootstrap loader that has been loaded into the ATmega328P chip before it is put in an Arduino board. This allows it to be programmed via the serial port.) If you put an ATmega328P straight from Atmel into the board you would not be able to program it via the Arduino IDE. Your Pro Micro uses an ATMega 32U4 PB4 is on pin 28 of this chip (Which seems to go to a connection labled D8 (on pin 2 of JP7) on the Pro Micro board from looking at the schematic. MISO on this chip is pin 11 of this chip which is PB3 when not being programmed from a normal programmer. This is labled MISO and is on pin 10 of JP6 I would have thought that the code would still be using PB4 on any type of Arduino. To confirm this you would have to look at the source code produced by the compiler for the two models of Arduino. It is difficult to find the information to look at the source code produced by the compiler. The transmitter and receiver I used are different models to the ones that you have but that should not make any difference. I have had a look at the source code link but it seems to use a signal D12 for transmit. I have no idea how this is mapped to a physical port on the chip. I think you will have to wait for somone that programs in "C" to help you. (I work with assembler.)

EDIT I think I have found that on an ATmega32U4 that D12 maps to port D bit 6 (PD6) This pin (Pin 26) is not brought out to a pin to connect to on your board. You may be able to solder a wire to it but it is still possible it will not work. The Arduino Leonardo uses this chip and this signal is available on the pins on the board.

Les.
 
Last edited:
I think you will have to wait for somone that programs in "C" to help you.


Does this mean that if I can get help from someone familiar with "C" then I might be able to alter the RH_ASK.h code in the RadioHead library of the Aduino IDE to change the output pin to an available pin on JP6 or JP7 of the ProMicro?

EDIT: I think I see where the pin is assigned.

RH_ASK(uint16_t speed = 2000, uint8_t rxPin = 11, uint8_t txPin = 12, uint8_t pttPin = 10, bool pttInverted = false);

/// The configure transmitter pin
uint8_t _txPin;

Maybe I can change the txPin number to an available pin on JP6 or JP7 of the ProMicro. If so, how would I know what pin number to put for txPin in the RH_ASK constructor to map to a pin on JP6 or JP7 of the ProMicro?
 
Last edited:
I Googled something like "IO pin mapping on ATmega32U4" Which is used on your Pro Micro (And also the Leonardo) I Did the same for the ATmega328P which is used on the Uno. I did think about suggesting changing the txPin asignment but as I know nothing about how "C" works I do not know if it is that simple. You may have to change a bit in the data direction register of the port you are using to make it an output. (Set the bit to a "1" to make the pin an output.) I have no idea how to do this with "C"

Les.
 
data sheet shows that receiver output = vcc/2 so you didnt blow anything, which is lucky as not most chips do this

for changing h file, i would suggest trying it!

also if you have problems finding pins you can use a blinky code and volt meter, ie...
while (1)
{
digitalwrite(pin,high);delay(1000);
digitalwrite(pin,low);delay(1000);
}

Part of me wonders if the h file is required or just a protocol to help, I can only half read the h files , but it would be interesting to see if after you find the blinky pin hook it to transmitter data pin, and see if it is able to pass through to the receiver, (leave receiver pin floating when testing to ensure PI is not pulling it to ground)
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top