If your device moves around how can you find its location and/or orientation?phonexyz

Class 31: 20 June 2015

Using your smartphone as an orientation sensor for the Raspberry Pi.

Harness its accelerometer & magnetometer data, and send its orientation by wifi to the Pi.

We experiment with the concepts like PITCH, ROLL and COMPASS BEARING that we will use again with our own Inertial Movement Unit directly on the Pi in future weeks.

1

DSCN6037

 

 

 

 

 

 

 

INSTRUCTIONS DOC

Instructions2

Presentation

 

Class 32: 4 July 2015

How far did we move? Stepper motors. Counting the pulses used to instruct the wheels to turn around.

Stepper motor.drive-module-board-uln2003

A script to try. (For the adventurous)

Wire from motor board to rpi breadboard:

  • “5-12 +“   to +5V (bottom red rail?)
  • “5-12 -“  to GND (bottom gnd blue rail?)
  • IN1  to GPIO #8 (ie “CE0″)
  • IN2  to GPIO #23 (ie “P4″)
  • IN3  to GPIO #24 (ie “P5″)
  • IN4  to GPIO #7 (ie “CE1″)

 

 

Class 33: 25 July 2015

Raspberry Pi as a Live Internet Radio

Instructions

Hint: Remember RPI wants to send audio to HDMI if HDMI is plugged in, to audio jack if HDMI is not plugged in!

 

Class 34: 1 Aug 2015

PS2 female connector pinout

PS2 keyboard on Arduino

Preparation:   Download PS2Keyboard.zip (version 2.4) from HERE.   Unzip it and move the resulting PS2Keyboard folder to inside the …/sketchbook/libraries/  folder of your arduino installation.

So where is your sketchbook area on your PC. Start arduino IDE, and select File/Preferences. The top entry will show where your sketchbook directory is. It may be “…./sketchbook” or “…..\arduino”

ps2pinsWe will connect arduino pin D8 to “Data”
and arduino pin D3 to “Clock” (also known as the IRQ in this project)
… and of course arduino +5V and GND connected as well.

We use the “example” called “Simple_Test”, but line 31 needs to be corrected to
correctly reference “IRQpin = 3″ (not 5) to match what we connected.
So edit that line and SAVE your (very easy) project as (say) “kb1″.

It should run. Open the Arduino’s terminal to see key output.

 

Class 35: 15 Aug 2015

Remote control of RPi via browser on PC – WebIoPi

 

WebIOPi is included on BS4.  … but keep reading …

PREPARATION:  On the web, WebIOPi is currently broken (for 40-pin boards). If you use only a 26-pin GPIO board then the already installed WebIOPi on your BS4 will suffice. If you use BS3 or earlier, or your board is a Bplus or a RPI2 40 pin one,  download this version instead, and put it on RPi desktop. Installation and running instructions are HERE.

 

You need your RPI with at least one LED output and one switched input and one jumper.

LED. Either:

  • The one LED on CE1 that we mounted to breadboard 26 April 2014. It’s on our website.
  • A LED you add now (LED plus resistor of about 200 to 500 ohms) – use CE1 again.
  • 44BEST: the stepper motor’s controller board (without motor) that we used a couple of months back. Wired exactly as on 4 July 2015 on our website. It makes a neat 4-led board.

SWITCH:

A switch to pin P0 (#17) as shown. The resistors provide pulldown plus protection in case you set that pin as an output, drive it low, and press the button (high) at same time. :-(

A JUMPER:

From pin P4 (#23) with the controller board connection
to pin P3 (#22).
Actually a resistor instead of simply the jumper wire would be good protection here too. 200-1500 ohms.

 

 

Class 36: 5 Sept

Virtual GPIO

The arduino gets a sketch to make it into a dumb but competent GPIO device. The arduino stays plugged into PC’s USB port. The PC (programmed in python) can now use the arduino as a GPIO. Almost identical programming to a Raspberry Pi controlling its GPIO.

Today (Part 1) – PC controlling:

  • Demo 01 – PIR burglar detector
  • Demo 02 – Analog light detector
  • Demo 03 – Tone (buzzer)
  • Demo 04 – RC servo motor
  • Demo 05 – Stepper motor
  • Demo 06 – Infrared receiver
  • Demo 07 – LCD16x2 display (I2C)

Download the 7 python demo script files from the scripts page as usual. The connection diagrams are included there.

The full specification document for Virtual GPIO is HERE.

 

Class 37: 26 Sept

Virtual GPIO on your PC part 2.  How far did we move? How far are we away?

Wheel encoders. Counting the pulses that the wheel REALLY turned,  Sonar.   LED PWM.

  • Demo 08 – Interrupt based counter
  • Demo 09 – Sonar
  • Demo 09b – (improved) sonar
  • Demo 10 – Quad Encoder (up/down counter) – fast
  • Demo 10b – Quad Encoder – slow (watchable)
  • Demo 11 – PWM to dim a LED

Setting up:

Leave the stepper motor board connected to pins 2-5 as per demo05. Strip away all other “gadgets”. Even remove the actual motor itself, leaving just the board with 4 leds.

Now connect the HR-04 ultrasonic ranger (the “bug eyes”) like this:

  • VCC – to arduino +5V
  • Trig – to arduino pin d7
  • Echo – to arduino pin d6
  • GND – to arduino GND

Python demo scripts for this part 2 class – see scripts page as usual.

Also fetch from the scripts page the arduino files. Last class I programmed the arduino of anyone who wanted. This week we see how to do it for yourself.  Note that all these 20 arduino files are to live ALL IN THE ONE SKETCHBOOK FOLDER, …/arduino/virtGPIO/ or …../sketchbook/virtGPIO/. Even the ones that look like library files DON’T go the the libraries folder – they all live together in ../virtGPIO. More in class.

Class 38: 3 Oct

Virtual GPIO on your PC – part 3:

  • keypad12. Keypad Pins as shown L-R
  • R1 R2 R3 R4 C1 C2 C1
  • Arduino pins 2  3  4  5  6  7  8

Our python library and script is nearly identical to Raspberry Pi keypad script of last May.

 

 

DSCN5518

 

 

13. TFT LCD 1.44 inch SPI

LCD Supply 5.0V,  LCD Logic level on pins: 3.3V

39753-3

Arduino supply 5.0V, logic 5.0V.  (But a 3.3V power output is available.)

Problem: The arduino logic levels are 5V, and the LCD pins are not “5V tolerant”.

Solution: Use a “logic level shifter” This one has 4 through-connections for logic. That is enough (JUST) for our job. One side of the board works at 3.3V, the other at 5V. It’s bi-directional.

 

The library and 6 demo scripts are nearly identical to the ones we used with Raspberry Pi on last May.

ARDUINO           LEVEL SHIFTER            LCD

+3.3V  ----------------------------------  LED
13 (Sclk)--------- HV1  LV1 -------------  SCK
11 (Mosi)--------- HV2  LV2 -------------  SDA
+5V    ----------- HV
+3.3V  -----------------LV
GND    ------------GND--GND
9      ----------- HV3  LV3 -------------  A0
+3.3V  ----------------------------------  RESET
10 (SS)----------- HV4  LV4 -------------  CS
GND    ----------------------------------  GND
+5V    ----------------------------------  VCC

NOTE: The backlight LED pin is simply tied high (+3.3), so LED stays ON.

And RESET is also tied high, so hardware reset (pulse down) is impossible. The library tries to do a “software reset”.

(We should wish for a 6-channel logic shifter. But we made do with 4 channels.)

 

Class 39: 17 Octdevices

8×8 LED display

INSTRUCTIONS

24 Oct

 

The “internet of things” – IoT.

 

31 Oct

 

Inertial Measurement Unit. Part 1. Getting it working on the Raspberry Pi.
There are only 4 pins to connect. Note we DON’T connect Vin. We use 3.3 instead.

IMU             RPI
=====           =====

Vin                        n/a
3V3-------------3.3V
GND-------------GND
SCL-------------SCL
SDA-------------SDA
SDO/SA0                    n/a
CS1                        n/a
CS2                        n/a

There are 3 chips on this board:

  • BMP180 at I2C address 0x77 = air pressure & temperature (ie 2 values to read)
  • LSM303D at I2C address 0x1D = both accelerometer and magnetometer (3 values each in X Y Z)
  • L3GD20 at I2C address 0x6B = gyroscope (3 values in X Y Z)

Pretty clever for 2 signal wires!

 

To look at:

  • Our friends roll, pitch, yaw (compass heading) – remember those from class 31?
  • We need to agree on our co-ordinate axes – which is X Y Z direction? Executive decision, then make the maths match that.
  • “RAW” reading from each unit.
  • We need to convert those raw figures to useful human-friendly figures of:
    • height asl
    • degrees of roll and pitch
    • compass heading.
  • Altitude using pressure & temperature & the weather bureau website.

Go back to Class 31, and re-read the second half of the “presentation” file, regarding axes and frames of reference.

Presentation

 

7 Nov

Inertial Measurement Unit. Part 2. Testing its limits on the Raspberry Pi.300px-Earths_Magnetic_Field_Confusion.svg

  • Watching on-screen plots of our measurements.
  • Filtering “noisy” data.
  • Find real 3D direction of earth magnetic lines.
  • Why compass needs serious corrections for “declination” (true N vs magnetic N), and for roll & pitch angles.
  • Getting gyro/rotating data to co-operate with accelerometer/gravity data for bumpy roll/pitch readings.
  • Can we derive velocity (in 3D) by keeping track of accelerations?
  • Can we then derive distance travelled (in 3D) by keeping track of velocities?

Graphic plotting: For this class we will need “python-matplotlib” installed on the RPI. This is included in BS4 version of SD card, but not in BS3. Use synaptic to install if you are not using BS4.

Presentation

 

21 Nov

Access to your network (webserver, WebIoPi, mpd, any IoT device) from outside your firewall: port forwarding.

PPT for class

This class is instructional tutorial only. You do not need your arduino nor your raspberry pi.

 

22 Nov

Last Will & Testament

ip-notif.7z

End of series “Bot Software: Raspberry Pi and Arduino”

 


 

 

2016:

From March 2016: “Bot Software: Internet of Things”

Eg see APC Magazine #422, December 2015, page 104, article “Arduino Wifi: Part 1″.  They have stolen our first 2016 class!  :-)

Comments:

  • ESP-01 module easily available on eBay (China) – under $4.
  • 3.3V power regulator – can use 3-pin Jaycar LM3940 $4.  3.3V power to esp8266 is COMPULSORY, at 250mA min.
  • I don’t like that they interface arduino 5V (pins 10/11) to esp8266 tx/rx (all esp8266 should be 3.3V). But they seem to get away with it.
  • But we will work more with esp-12 and/or “devkit 1.0″ (nodemcu) modules.