Raspberry Pi
Reference info
Configure SSH and VNC to your Raspberry Pi: https://www.raspberrypi.org/documentation/remote-access/ssh/
Default login = pi and default password is raspberry
Setup Raspberry
The different model of Raspberry hardware are on https://www.raspberrypi.org/products/
Upgrade to the last Raspberry Pi OS
See reference page of Raspberry Pi OS: https://www.raspberrypi.org/software/
Install Raspberry Pi Image manager on MAC then copy with that tool the last OS image to the SD Card and install it on Rasberry Pi Hardware
When the Raspberry boot for the first time it will request to update it to latest current OS minor patch, it can take time. Configure also the Wifi
Activate on config, the SSH and VNC for remote connection to it.
Configure the language and regional settings. This is important because this can cause issue with Python later on
// To change the locals and regional settings
$ sudo raspi-config
// Install Yarn package manager:
$ curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
$ sudo apt-get update && sudo apt-get install yarn
It can happen you have issue with regionals, look here: https://www.raspberrypi.org/forums/viewtopic.php?f=50&t=11870
Each Raspberry hardware is running a different max version of Rasbian OS.
Raspberry Pi 3 is running on ARM71 and support "Raspbian GNU/Linux 8 (jessie)"
Install Git
Install Git ->
sudo apt-get install git-core
Which Hardware and Software Version you have
// Which Hardware Version
$ cat /proc/cpuinfo
// AT the end under Model, you have the version you run
// Check the Software Version of Raspian you are running
$ cat /etc/os-release
// last version on 01/01/2021 -> v10, named buster
// Check the processor architecture type on your Raspberry
$ uname -m
Upgrade wiringPi C Lib (for GPIO)
Ref Link: http://wiringpi.com/wiringpi-updated-to-2-52-for-the-raspberry-pi-4b/
$ wget https://project-downloads.drogon.net/wiringpi-latest.deb
$ sudo dpkg -i wiringpi-latest.deb
$ gpio -v
$ 2.52
To find the Pin-out:
$ gpio readall
Install Docker
To install docker on Raspberry pi: https://phoenixnap.com/kb/docker-on-raspberry-pi
$ sudo apt-get update && sudo apt-get upgrade
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
$ sudo usermod -aG docker pi
// Verify ok
$ docker info
// Run a first app:
$ docker run hello-world
First Docker App
!! The images from docker hub, please select on the left side the ARM64 tag. So when you build a docker image you have to take care of the end where it will run
Illustration of a first Web App DOcker: https://blog.hypriot.com/getting-started-with-docker-on-your-arm-device/
Install Node.js
The installation of Node.js depend of the Processor on the Raspberry Pi.
Installation on Raspberry Pi 4
! Be sure you have first upgraded to the latest Raspberry pi OS, otherwise you can have issue to support limited version of Node.js because of lib gcc++ incompatible used on old Raspberry pi OS.
Illustration steps on https://thisdavej.com/beginners-guide-to-installing-node-js-on-a-raspberry-pi/
$ curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -
$ sudo apt install -y nodejs
$ sudo node -v
// npm is part of node so you should check you have it
$ npm -v
// if you don't have it, it means installation doesn happen on good way
Installation on Raspberry Pi 3
Additional info on the type of processor on Raspberry: https://www.makersupplies.sg/blogs/tutorials/how-to-install-node-js-and-npm-on-the-raspberry-pi
Different sites
C programming on Raspberry
Reference Documentation
Your First C Prog on Raspberry
// First program in hello.c
#include <stdio.h>
int main(){
printf("Hello, World! \n");
return 0;
}
// Compile
$ gcc hello.c -o helloTest
$ chmod + helloTest
// Run it
$ ./helloTest
Library Wiring Pi: WiringPi is PRE-INSTALLED with standard Raspbian systems
// TO check the version of gpio
$ gpio -v
Other Apps in C
Blink a Led Written in C
Reference Material: http://wiringpi.com/examples/blink/
// blink.c file
#include <wiringPi.h>
int main (void)
{
wiringPiSetup () ;
pinMode (0, OUTPUT) ;
for (;;)
{
digitalWrite (0, HIGH) ; delay (500) ;
digitalWrite (0, LOW) ; delay (500) ;
}
return 0 ;
}
// Compile and execute
$ gcc -Wall -o blink blink.c -lwiringPi
$ sudo ./blink
Other Apps in Node.js
Integrate with Led Bredboard: https://blog.alexellis.io/getting-started-with-docker-on-raspberry-pi/
Run an Alpine image and interact with it
$ docker run -ti arm32v6/alpine:3.5 /bin/sh
For more info see test command on https://blog.alexellis.io/getting-started-with-docker-on-raspberry-pi/
Integration with Input-Output
GPIO
General Purpose Input/Ouput pinout: https://www.raspberrypi.org/documentation/usage/gpio/
Make a led Blinking
Check tuto: https://www.w3schools.com/nodejs/nodejs_raspberrypi_blinking_led.asp
Application written in javascript on node.js
//Create you nmp project
//Install the on/off node module on project
$ npm install onoff
//create the index.js file with code to light GPIO 4
var Gpio = require('onoff').Gpio; //include onoff to interact with the GPIO
var LED = new Gpio(4, 'out'); //use GPIO pin 4, and specify that it is output
var blinkInterval = setInterval(blinkLED, 250); //run the blinkLED function every 250ms
function blinkLED() { //function to start blinking
if (LED.readSync() === 0) { //check the pin state, if the state is 0 (or off)
LED.writeSync(1); //set pin state to 1 (turn LED on)
} else {
LED.writeSync(0); //set pin state to 0 (turn LED off)
}
}
function endBlink() { //function to stop blinking
clearInterval(blinkInterval); // Stop blink intervals
LED.writeSync(0); // Turn LED off
LED.unexport(); // Unexport GPIO to free resources
}
setTimeout(endBlink, 5000); //stop blinking after 5 seconds
// Then you can run the project by
$ node index.js
Take Input and Set Output
Tuto on: https://www.w3schools.com/nodejs/nodejs_raspberrypi_led_pushbutton.asp
// create the index.js file to take input buton and light led
var Gpio = require('onoff').Gpio; //include onoff to interact with the GPIO
var LED = new Gpio(4, 'out'); //use GPIO pin 4 as output
var pushButton = new Gpio(17, 'in', 'both'); //use GPIO pin 17 as input, and 'both' button presses, and releases should be handled
pushButton.watch(function (err, value) { //Watch for hardware interrupts on pushButton GPIO, specify callback function
if (err) { //if an error
console.error('There was an error', err); //output error message to console
return;
}
LED.writeSync(value); //turn LED on or off depending on the button state (0 or 1)
});
function unexportOnClose() { //function to run when exiting program
LED.writeSync(0); // Turn LED off
LED.unexport(); // Unexport LED GPIO to free resources
pushButton.unexport(); // Unexport Button GPIO to free resources
};
process.on('SIGINT', unexportOnClose); //function to run when user closes using ctrl+c
Based on Input Create a cryptographic key
var Gpio = require('onoff').Gpio; //include onoff to interact with the GPIO
var LED = new Gpio(4, 'out'); //use GPIO pin 4 as output
var pushButton = new Gpio(17, 'in', 'both'); //use GPIO pin 17 as input, and 'both' button presses, and releases should be handled
pushButton.watch(function (err, value) { //Watch for hardware interrupts on pushButton GPIO, specify callback function
if (err) { //if an error
console.error('There was an error', err); //output error message to console
return;
}
LED.writeSync(value); //turn LED on or off depending on the button state (0 or 1)
});
function unexportOnClose() { //function to run when exiting program
LED.writeSync(0); // Turn LED off
LED.unexport(); // Unexport LED GPIO to free resources
pushButton.unexport(); // Unexport Button GPIO to free resources
};
process.on('SIGINT', unexportOnClose); //function to run when user closes using ctrl+c
Web Socket Button Input to turn on/off Led
Tuto: https://www.w3schools.com/nodejs/nodejs_raspberrypi_webserver_websocket.asp
Temperature & Humidity DHT11 Sensor
Reference Material: https://github.com/momenso/node-dht-sensor
// Create the node.js project
$ npm init
$ npm install node-dht-sensor
// Create the following index.js code
var sensor = require("node-dht-sensor");
sensor.read(11, 4, function(err, temperature, humidity) {
if (!err) {
console.log(`temp: ${temperature}°C, humidity: ${humidity}%`);
}
});
// Run the program:
$ node index.js
Last updated
Was this helpful?