So, I’m writing these notes while putting together a small robot powered by a Raspberry pi.

Installing wiringPi
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v

Installing Visual Studio Code (yes, VSCode can run on a pi!)(https://code.visualstudio.com/docs/setup/raspberry-pi)
sudo apt update
sudo apt install code

Set up C code in a single c file (to test)
compile with gcc -Wall -o piBot main.c -lwiringPi

gcc -o piBot main.c -lwiringPi -lm


run using ./piBot
Single LED connected between pin 11 (GPIO 17) and pin 6 (Ground)

#include <wiringPi.h>
#define PIN_DIRECTION 28  // GPIO 20 - Direction
#define PIN_STEP 29       // GPIO 21 - Step
#define PIN_MS1 15        // GPIO 14 - MS1
#define PIN_MS2 16        // GPIO 15 - MS2
#define PIN_MS3 1         // GPIO 18 - MS3
#define speed 800

int main (void)
{
  wiringPiSetup () ;
  pinMode (PIN_MS1, OUTPUT);
  pinMode (PIN_MS2, OUTPUT);
  pinMode (PIN_MS3, OUTPUT);
  pinMode (PIN_DIRECTION, OUTPUT);  // GPIO 20 - Direction
  pinMode (PIN_STEP, OUTPUT);       // GPIO 21 - Step

  digitalWrite (PIN_MS1,  LOW);
  digitalWrite (PIN_MS2,  LOW);
  digitalWrite (PIN_MS3,  LOW);
  digitalWrite (PIN_DIRECTION,  HIGH);
  
  for (;;)
  {
    digitalWrite (PIN_STEP, HIGH) ; delayMicroseconds (speed) ;
    digitalWrite (PIN_STEP,  LOW) ; delayMicroseconds (speed) ;
  }
  return 0 ;
}

Links I worked from…

mpu6050: http://www.pibits.net/amp/code/raspberry-pi-mpu-6050-c-example.php

Bluetooth: https://github.com/petzval/btferret

Stepper: https://crish4cks.net/a-simple-c-library-to-drive-a-stepper-motor-using-the-raspberry-pi/

Display the raspberry pi config; sudo raspi-config

Edit the Raspberry pi boot config.txt

sudo apt-get install libi2c-dev

detect i2c devices connected to the Pi; i2cdetect -y 1


Discover more from

Subscribe to get the latest posts sent to your email.

Leave a comment

Trending