Project

General

Profile

Any help with RFM69 on RasPi is greatly appreciated

Added by JohnnyMac 9 months ago

Hello all,

I've been searching your forums for the past few months now and decided it's time to make an account and finally get help since I'm currently stuck.

Background:
I'm creating an IOT using a Raspi 3B as my gateway so I can eventually control everything in my home from a tablet or phone. Currently I have a RFM69HCW (because I want to TX/RX from sensors I put outside possibly a few hundred meters away but may switch to LoRa radios later on) connected to my Raspi and also have 2 Arduino Uno's (If I can get 2 Arduino's to TX/RX info and be identified somehow then I can connect however many sensors or nodes I want in the end and will know how to TX/RX to and from each of them, that's my thought anwyays) each have a DHT11 moisture/temperature sensor connected (for now) and a paired RFM69HCW. I have the Arduino side of the project working, both Arduinos have TX and RX loops so I can put them in a sleep mode (eventually) and not waste battery power or whatever they may be connected to at the end of the project.

My current trouble is the Raspi linux/python side (don't yell at me, I don't know the platform as well as an Arduino but am learning but still don't know the difference between the two). I've been following the Jeelabs "RFM69 on Raspi" pages ( https://jeelabs.org/2015/05/20/rfm69-on-raspberry-pi/ ) and have been doing OK so far. The only real problem I've ran into is that Gordon's repo wasn't working but after a quick google search I found the one on GitHub and cloned it without a hitch. Now I'm kind of stuck mostly because I'm a newbie with this platform and don't really know what to do after reading the "Using WiringPi with RasPi RF" page ( https://jeelabs.org/book/1521b/ ) because after I cloned wiringPi onto my Raspi. I will say this, I'm not looking to be spoon fed...however I am looking for help because I am very interested in this platform as I see the possible strong potential it has for things I'd like to do with it, and learn from, but will admit I'm very green when it comes to Raspi world. I've searched google and your forums along with lowpowerlab's but am still kind of stuck in the mud with my wheels spinning. I just kind of need a good push and would be nice to have someone or "someones" to ask questions to throughout the week. I don't anticipate someone to wait on me hand and foot but am looking for a little help learning the platform a little better and help with the RFM69 on Raspi set of pages.

I've gotten to the step "WiringPi needs to be downloaded and installed on the Raspberry Pi before it can be used. See these instructions for how to do this." but am very confused with what exactly to do after I've installed wiringPi. I've been looking at the following pages for help:

http://rdepablos.merlitec.com/mixed/rfm69-library-for-raspberry-pi
https://www.mysensors.org/build/raspberry
https://github.com/abouillot/HomeAutomation/tree/master/piGateway
https://jeelabs.net/boards/7/topics/7481
https://jeelabs.net/boards/7/topics/7186
https://jeelabs.net/boards/7/topics/7299
https://jeelabs.net/boards/7/topics/7679
http://embello.jeelabs.org/
among many many others...

I'm also unsure what "make" and "GCC" are or why I need them. I read in one of the posts on these forums ( https://jeelabs.net/boards/7/topics/7299 ) that someone was using a rfm69 with raspi as well and said they had make and GCC installed which I'm assuming I need as well. Overall I'm looking for a good push in the right direction with on-going guidance if possible. Thank you very much.


Replies (10)

RE: Any help with RFM69 on RasPi is greatly appreciated - Added by Rolf 9 months ago

Should not be that big problem, I am using sucessfully RF69 with a Raspberry Pi, precisely that RFM69CW Board from the Jeelabs Shop:
You have already found the instruction pages on the Wiki. For further proceeding, it will be useful that you describe at which point exactly you have a problem.

Comment to what I understood up to now: "gcc" and "make" are the C-compiler and tool for compiling C-sources. You will need them to compile the source code mentioned in the instructions. First you have to install them:

As root do:
apt-get install gcc
apt-get install make

If you do not know how to become a root user, do it with sudo:

sudo apt-get install gcc
sudo apt-get install make

If the debian installation on your Raspi is a bit older, it may happen you run in problems. In this case update the installation before trying to install gcc and make another time:
sudo apt-get update
sudo apt-get upgrade

(Or as root, without preceedimg "sudo")

Also you have to enable SPI on your Raspi, because the RF69 board is driven via SPI. Do this with the Raspi configuration tool (raspi-config ?)

Success!

Rolf

RE: Any help with RFM69 on RasPi is greatly appreciated - Added by JohnnyMac 9 months ago

The Jeelabs board you posted is almost identical to the breakout boards I bought from Adafruit but is just a bit smaller due to the surface mount components. ( I'm not sure how to properly hyperlink text like you did when you linked the jeelabs RFM69 shop page to text "the Jeelabs shop:" )
https://www.adafruit.com/product/3071?gclid=EAIaIQobChMImpfbu8CA2QIVgx2BCh15BQDQEAQYByABEgJ7ZvD_BwE

I just tried to install GCC and make but apparently they've already been installed somehow. Not sure when but I never typed "sudo apt-get install GCC" or "sudo apt-get install make". I did update and upgrade my pi this past Tuesday when I was following the wiki page. I apparently have already installed raspi-config as well as all 3 were "not upgraded" and are showing that they're already the newest version. So that part is all set.

One main issue I'm having is visualizing how this all works on a RasPi. In Arduino language I just plug in my Uno, connect to it's respective com port, open the IDE, type my code, upload it, and I'm off to the races. Do I do the same thing here on the RasPi but using Python or scratchpad or PERL or the terminal? I'd assume not the terminal. It's safe to assume that using the terminal is for calling or opening different programs and files kind of like going into the "My Computer" shortcut on a Windows desktop PC? One thing I've been wondering is where everyone learns how to use a RasPi for more than just simple projects or tinkering. I bought "The Linux Command Line" book in hopes it'd help me with the basics and a much more in-depth view of the linux world and what I can do with it but have yet to start reading it unfortunately. Taking 5 college classes this semester and working 15-16 hours a week while maintaining some sort of social life with my girlfriend leaves me with not much time for anything else.

So back on track, where I'm stuck. After I installed wiringPi is where I really have no clue what to do next. Like I mentioned above, where am I writing the code? I also noticed there's chunks of code here and there and really don't understand why or what it really does? How do I reuse the RF69 driver used in the embello project and how do I install it? It then says " Being Linux, the build process is completely different though, and uses this Makefile: " and I really have no clue what that means or what a makefile is. I now know what make is, thanks to you, so is that typed into terminal (the lines of text after that comment)?

How do I know if I have all of these libraries installed that are needed for the linux text application a few lines down?
#include <stdio.h
#include <stdint.h
#include <errno.h
#include <wiringPi.h
#include <wiringPiSPI.h
#include "spi.h"
#include "rf69.h"

I just cloned the embello repo so I can run the sample build when I get there and once there I think I should be ok for a little bit.

One other question, physical wiring. I've tried following the Jeelabs wiki but am confused on a few things.
My board has the following pins:
VIN, GND, EN, G0, SCK, MISO, MOSI, CS, RST, and G1, G2, G3, G4, and G5.
From my understanding all I need are the 4-wire SPI connections SCK, MISO, MOSI, and CS/CE/NSS with GND and Vin(3.3v/5v) but am confused about the DIO pins.

My current wiring on my RasPi 3B is like so with my Adafruit breakout board ( The RasPi on the wiki is the 26 pin original RasPi v1 ):
Vin3.3v Pin 17 (5v is Pin 2)
GND Pin 25
SCK Pin 23
MISO Pin 21
MOSI Pin 19
CS Pin 24
RST Pin 18

1) What is DIO 0 and 2? It says we're using these for interrupts but the pins are labeled a bit different on my board.
2) NSS, CE, and CS are the same thing as far as my knowledge goes, right? Because on the wiki it says "(the careful viewer will note that one wire from pin 22 to NSS still needs to be added)" but shows MISO in the pin 22 spot.
3) The wiki says to not use the 3.3v pin with the HCW board so will I be safe using the 5v pin or should I just keep the power output down?
4) Would it be better to just but the RFM69CW board and following the wiki on creating a small shield? I can replicate one very easily.
5) If I reboot my Pi but my sensors on my Arduinos are still transmitting data will the RasPi still pick it up or will I have to run the file with all the code in it again? I don't get how any of that works either.

I think that is enough questions for now which will allow me to get a lot more progress going. I will post more as I run into them. Thank you VERY much for the help. It's greatly appreciated. I can't stress that enough.

RE: Any help with RFM69 on RasPi is greatly appreciated - Added by Rolf 9 months ago

For today just a short answer, I am busy with a lot of other things. Attached is a diagram that shows how to connect the RF69-breakout to the Pi.

Secondly, you should get familiar with the "command line" under Linux. Use "xterm" or something similar and you can type in commands directly. Look for a source of the program "hello world" in C language, should be just 4 or 5 lines. An compile it: cc -o hello hello.c. cc (or gcc) ist the C-compiler, hello.c the source file and "-o" means, the following (hello) will be the final "binary/executable" program. And then execute the program, by typing ./hello. ",/" means the path you are just on.

Compiling with a Maklefile is even easier. In your path you will find a file with that name, it contains all the information needed to compile the source. You just have to type in make and the tool "make" does the compilation, based on the information in the Makefile.

Just an explanation of the following:
#include <stdio.h
#include <stdint.h
#include <errno.h
#include <wiringPi.h
#include <wiringPiSPI.h
#include "spi.h"
#include "rf69.h"

The first three libraries are automatically included, when gcc is installed. The 2 "wiringPi"s are included with the installation of wiringPi. And the last 2 , spi.h and rf69.h, are in the souce directory you downloaded from embello. If not, you have to find them there and include them in your path.

How to download embello? First install the "git" tool (apt-get install git). Then go with the browser to the embello repository on GitHub:
https://github.com/jeelabs/embello/
You find this link by looking for "embello" on the Jeelabs Wiki. Then on your raspi (command line, xterm) go to that directory, where you want to have embello as a subdircetory and type:
git clone https://github.com/jeelabs/embello/
You do not have to be root for that step. With embello on your Raspi, you have all the software you need.


RE: Any help with RFM69 on RasPi is greatly appreciated - Added by JohnnyMac 9 months ago

I appreciate the diagram. I was able to connect my Adafruit breakout to my Raspi using that and figuring out that your IRQ is G0 on my breakout board.

So following the wiki, I get to the line that say:

A sample build, assuming you have cloned the embello repository from GitHub:

$ cd embello/lib/test-raspi-linux
$ make
g++ -I../arch-raspi -I../driver rf69spi.cpp \
-lwiringPi -lwiringPiDev -lpthread -o rf69spi
$

My question is how do I enter all of that into xterm? The line "$ cd embello/lib/test-raspi-linux" worked fine, obviously. But when I typed in:

$ make
g++ -I../arch-raspi -I../driver rf69spi.cpp \
-lwiringPi -lwiringPiDev -lpthread -o rf69spi

I get this:

make: *** No rule to make target 'g++'. Stop."

Any clue what I'm doing wrong? I typed all of that into one line because that's what it looks like how it's supposed to be typed?

$ make g++ -I../arch-raspi -I../driver rf69spi.cpp \ -lwiringPi -lwiringPiDev -lpthread -o rf69spi

Right now I'm just trying to see if my RasPi will get the "Hello world" that my Arduino is sending out. Also looking at the "test-raspi-linux" file in text editor where is the baud rate set? If I had to guess it would be the "4000000" in this chunk of code:

int main () {
wiringPiSetup();
int myFd = wiringPiSPISetup (0, 4000000);

Also, I read down to line "Note: before trying any of this, make sure you have enabled SPI using the raspi-config", how do I do that? The wiki doesn't show how.

A common theme I'm noticing is that not much is in-depth in the wiki which to me means that a higher level of knowledge is required before going straight into something like this. Where do you all learn about the linux platform? Books? Youtube? Tinkering around with small projects first? I'm not even sure what half of the commands are like "-I" and I'm sitting here trying to digest and make sense of most of it with a Unix/Linux Command Reference from Fosswire.com in front of me trying to figure out what exactly the commands I'm typing are actually doing. So where did you learn how to use Linux?

I think that'll be enough questions for now. I appreciate the help. Thank you.

RE: Any help with RFM69 on RasPi is greatly appreciated - Added by Rolf 9 months ago

How to enable SPI? Use the tool for configuring the Raspi, on the command line it is raspi-config. But looks like you are not familiar with the command line in Linux. The best for learning this would be a friend to teach you, because this way you are coming quckily to the points where knowledge is missing. If this is not possible, install a Linux without a window system (X.11) on your Raspi and learn it by doing. I did this long time ago with Minix. Go to the Raspi download page and download "Raspbian Stretch Lite", that's a server version without X.11.

RE: Any help with RFM69 on RasPi is greatly appreciated - Added by JohnnyMac 9 months ago

I started googling raspi-config and how to use it and I've used it before, just had no clue what it was really even called and have since enabled the SPI interface in the raspi-config interfacing options.

I made a "Pi-cart" two years ago using a Pi zero without WiFi, a 4-port USB bus, the few required cables, and loaded Retro-Pie onto a 32GB SD card and made a retro gaming rig. I've done small projects before but am just looking for a little help and guidance. You said get a friend to teach me, well I figured I'd come here and make friends with someone who can help me with guidance while doing this project and others and so far the only person to respond and help has been you so I was hoping to at least become friends with you. I don't know anyone local in my area who knows much of anything about Linux except my old roommate whom I'm no longer on good terms with. Within a week or two I'd really like to get this IoT I'm working on to at least TX and RX with my Arduino UNOs, or at least be able to receive an intelligent signal from one of my Arduino UNOs.

The wiki also doesn't show how to set baud rates within the github repo they provided of the test program. If I can get my controllers to TX and RX anything intelligible then I shouldn't be very far from where I need to be. Once that happens then I can sit back and take a look at the bigger picture and realize what I need to know in order to do what I need to do. A great pre-calc teacher once asked my class if they knew why we were learning pre-calc, we all said no. So he showed us some problems relating to real world issues, mainly to do with physics based calc, and ask us to solve them. Unsurprisingly none of us knew how and that's when he told us that's why we're learning pre-calc first. That being said, I see it as a very important step for me to at least get my radios talking and then look at problems that I'm having a real issue with due to lack of Linux based knowledge rather than focusing on me getting stuck with, and not understanding, the verbiage used in Linux vs. C++ programming. Some of it's the same, just different ways of getting to where you need to be using different verbiage.

I hope you will help me to at least get my radios transmitting "Hello world!" or whatever the test program file sends. I thank you for your help and guidance thus far. I'm also concurrently reading The Linux Command Line so please don't think I'm not helping myself first before asking questions. Thanks again.

-John

RE: Any help with RFM69 on RasPi is greatly appreciated - Added by JohnnyMac 9 months ago

So I've made a tiny bit of progress after enabling the SPI interface. Any clue why it failed?

RE: Any help with RFM69 on RasPi is greatly appreciated - Added by JohnnyMac 8 months ago

Any help with the memory allocation problem I'm having?

RE: Any help with RFM69 on RasPi is greatly appreciated - Added by Rolf 8 months ago

In the Makefile change this line:

LDLIBS = -lwiringPi -lwiringPiDev -lpthread

to:

LDLIBS = -lwiringPi -lwiringPiDev -lpthread -fpermissive

RE: Any help with RFM69 on RasPi is greatly appreciated - Added by jcw 8 months ago

Since the error is that malloc is not defined, I'd try to fix that by adding #include <stdlib.h> at the top.

    (1-10/10)