Connecting a motor and 1602 LCD to a Raspberry Pi

From BitWizard Wiki
Jump to navigation Jump to search

This page describes the demo that can be found on the following youtube link: http://www.youtube.com/watch?v=zSQDuy-uu8I

Things we used

We chose a small DC motor which works on 5VDC, so we could power it directly from the RPi. It is, however, possible to connect an external power supply, to drive motors (or other stuff) which require a different voltage then the 5V provided by the Pi.

Steps to take

We split this up in two seperate scripts:

set_pwm

#!/bin/sh
pwmval=$1
bw_tool -C -t "BW spi 7fets PWM"
bw_tool -w 11:20
bw_tool -t "test: $pwmval"
bw_tool -a 88 -w 50:$pwmval

test_pwm

#!/bin/sh
./set_pwm 58
./set_pwm 48
sleep 4
for i in 50 60 70 80 90 a0 b0 c0 d0 e0 f0 ff ; do
  ./set_pwm $i
  sleep 0.5
done
sleep 1
for i in ff f0 e0 d0 c0 b0 a0 90 80 70 60 50 40 0 ; do
  ./set_pwm $i
  sleep 0.5
done

Put both scripts in your homedir, and run the test_pwm script as root, and you're done!