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
$ 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
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.
$ 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
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
//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
// 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
Temperature & Humidity DHT11 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
It can happen you have issue with regionals, look here:
Ref Link:
To install docker on Raspberry pi:
Illustration of a first Web App DOcker:
Illustration steps on
Additional info on the type of processor on Raspberry: