Solana DePIN Programs
DePIN Code Example of Solana.
Example Source Code: A DePIN example with Solana for "Selling Air".
Solana IoT
Required Hardware:
- 1 Raspberry Pi (Pi 5 recommended, Pi 4 works with different GPIO mapping)
- 1 SD card
- 1 SD card reader
- 1 USB-C cable for power
- 1 NPN transistor (with "AG" marking on back)
- 1 LED (for testing)
- 2-3 resistors
- 1 small motor
- Several jumper wires/cables
- 1 fan attachment (optional, for visual effect)
Software:
- Raspberry Pi OS
- Node.js (version 18.19)
- Solana CLI tools
Preparation
-
Prepare your Raspberry Pi workspace:
- Insert SD card into reader and connect to your computer
- Download and install Raspberry Pi OS using the Raspberry Pi Imager
- During setup, enable SSH and configure Wi-Fi credentials
- Insert configured SD card into Raspberry Pi and power it on
-
Season your Raspberry Pi with essential software:
- SSH into your Raspberry Pi using:
ssh username@raspberrypi.local - Update package repositories:
sudo apt update - Install Node.js:
sudo apt install nodejs - Install npm:
sudo apt install npm - Install NVM (Node Version Manager):
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash - Set Node.js version:
nvm use 18.19.0
- SSH into your Raspberry Pi using:
Base Circuit: LED Test
-
Assemble your basic testing circuit:
- Connect a white jumper wire from ground pin (3rd from top, right row) to the ground rail on your breadboard
- Place an LED on the breadboard
- Connect one side of the LED to ground through a resistor
- Connect the other side to GPIO 18 (or GPIO 589 if using Raspberry Pi 5)
-
Create your test program:
- Navigate to Documents folder:
cd Documents - Create a Python script:
nano LED.py - Add this code to turn LED on for 3 seconds:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, GPIO.HIGH)
time.sleep(3)
GPIO.output(18, GPIO.LOW) - Save (Ctrl+X, then Y)
- Run with:
sudo python LED.py
- Navigate to Documents folder:
-
Create a JavaScript version:
- Create a new directory:
mkdir led2 - Navigate to it:
cd led2 - Install the onoff package:
npm install onoff - Create a JavaScript file:
nano blink.js - Add code to blink the LED for 5 seconds
- Run with:
sudo node blink.js
- Create a new directory:
Main Course: Motor Circuit
-
Enhance your circuit for the motor:
- Remove the LED from your circuit
- Connect a wire from the 5V power pin to one side of the motor
- Connect the NPN transistor with a resistor to the GPIO pin
- Connect the other side of the transistor to the other side of the motor
- Connect the last pin of the transistor to ground
-
Test your motor circuit:
- Run your LED script to check if the motor spins
- If it spins continuously, you'll need to modify the code