-
Notifications
You must be signed in to change notification settings - Fork 241
Raspberry Pi interfacing
Thanks to the addition of the interfaces, it is finally possible to use PJON on a linux machine directly. For now only the ThoughSerial strategy has been ported for Raspberry Pi.
Create a file, copy inside this basic program and save it as test.cpp
.
#include <inttypes.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <wiringPi.h>
#include <wiringSerial.h>
#ifndef RPI
#define RPI true
#endif
#define PJON_INCLUDE_TS true // Include only ThroughSerial
#include "PJON/PJON.h"
int main() {
printf("PJON instantiation... \n");
PJON<ThroughSerial> bus(44);
printf("Opening serial... \n");
int s = serialOpen("/dev/ttyAMA0", 115200);
if(s < 0) printf("Serial open fail!");
if(wiringPiSetup() == -1) printf("WiringPi setup fail");
printf("Setting serial... \n");
bus.strategy.set_serial(s);
printf("Opening bus... \n");
bus.begin();
printf("Attempting to send a packet... \n");
bus.send(44, "B", 1);
printf("Attempting to roll bus... \n");
bus.update();
printf("Attempting to receive from bus... \n");
bus.receive();
printf("Success... \n");
return 0;
};
After you have created the file be sure to include in the same directory the PJON library directory.
Now it is necessary to compile test.cpp
program using gcc
.
Open the terminal and navigate to the directory where you created test.cpp
, then digit:
gcc test.cpp -o compiled_program -std=c++11 -lwiringPi
You should see a new file called compiled_program
.
Digiting: sudo ./compiled_program
you should see positive logging info appearing. Grab a level shifter and connect the Serial GPIO of your Raspberry Pi to exchange PJON packets with Arduino compatible devices.
- Update PJON 12.x to 13.0
- Addressing
- Configuration
- Data reception
- Data transmission
- Error handling
- IO pins setup
- Routing
- ATtiny interfacing
- ESP8266 interfacing
- Nucleo interfacing
- Raspberry Pi interfacing
- WINX86 interfacing
- Troubleshooting