Andrew Hudson

Saturday, 10 April 2021

Raspberry Pi from MacOS via SD Card

  • get the image: https://www.raspberrypi.org/software/operating-systems/
  • install the image: https://www.raspberrypi.org/documentation/installation/installing-images/mac.md
  • diskutil list to find out the rdisk that your SD is associated with
  • diskutil unmountDisk /dev/diskN replacing the rdiskN with the number of the disk your SD card is associated with
  • sudo dd bs=1m if=path_of_your_image.img of=/dev/rdiskN; sync replacing the rdiskN with the number of the disk your SD card is associated with. In my case this is sudo dd bs=1m if=/Users/andrew/Downloads/2021-03-04-raspios-buster-armhf-lite.img of=/dev/rdisk3; sync (you can see the progress by pressing ctrl+t)
  • this will put the image on /Volumes/boot which will be accessible from the command line
  • sudo diskutil eject /dev/rdiskN to eject the SD card.

Set up Wifi on the card

Format the SD Card

Install Nodejs on the raspberry pi

  • Need to SSH into the PI first then you can do the command line work.
  • Follow this as it worked for me: https://www.instructables.com/Install-Nodejs-and-Npm-on-Raspberry-Pi/
  • wget https://nodejs.org/dist/v14.16.1/node-v14.16.1-linux-armv7l.tar.gz
  • tar -xzf node-v14.16.1-linux-armv7l.tar.gz
  • cd node-v14.16.1-linux-armv7l/
  • sudo cp -R * /usr/local/
  • Check if node is installed node -v
  • Check if npm is installed npm -v

Install Apache

Johnny Five Button on Pi

  • npm install johnny-five raspi-io
  • create index.js
  • =======

Install Dependencies

  • sudo apt install vim nginx git
  • install rustup: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • install openssl and direnv: sudo apt install openssl direnv
  • cargo build --release
  • install more deps sudo apt install libprotobuf-dev protobuf-compiler
  • try again cargo build --release

Install the 64 bit version of the Raspberry Pi OS

Run Next with pm2

Code to run the button on raspberry pi with johnny-five

const five = require("johnny-five");
const Raspi = require("raspi-io").RaspiIO;
const board = new five.Board({
  io: new Raspi(),
});

board.on("ready", function () {
  const button1 = new five.Button("P1-7");

  button1.on("press", async () => {
    console.log("button1 pressed");
  });
});
  • Needs to be run with sudo privileges e.g. sudo node index.js
← Back to all blog posts
Edit this post on Github