Session 5 Slides - Wolf Den Electronics
Download
Report
Transcript Session 5 Slides - Wolf Den Electronics
Session 5
John Wolf
(WolfDenElectronics.com)
Course Objectives – We’ll Learn
Combinational Logic
Liquid Crystal Displays
Wireless
Bluetooth
XBee (another session)
Use of Interrupts
Stepper Motors
Complex software solutions
Back to the Arduino?
Digital I/O
header
USB
USB
processor
Atmel AVR
Computer
Power in
(9~12V)
Analog I/O
header
Microprocessor board with all the support electronics built-in on the board. Has
14 digital I/O and 6 analog I/O connections. USB port, power jack, and voltages
for support electronics attached to the board via the headers.
Liquid Crystal Displays
Very handy for robotics in general to
have on-board display of vital info
and ease of parameter changes
Most panels that control electronics
will have a display. LCDs are the
cheapest and easiest to code
LCD fundamental Spec
Based on Hitachi HD44780 Spec
Originally meant to use 8 data lines,
reduced to 4 by sending two nibbles
Backlight control and contrast control
Register select, Read/Write, Enable
Usually runs on +5V
Use LCD Library with Arduino to gets
past the complex serial stream
patterns
LCD line 1
LCD line 2
LCD Hookup
Arduino
Thermostat:
TC74 temp sensor
Set point buttons
Cooling fan
Buzz indicator
All displayed on
LCD
I2C Circuit Setup
Using 4.7k ohms
resistors is typical
Temp sensor
example
Notice analog in A4 and
A5 are dedicated to the
I2C bus when the Wire
Class is included
Mega uses different pins (SDA pin 20, SCL pin 21)
BlueTooth
Another 2.4GHz technology invented
in 1994 as a wireless RS232 bus for
short distances
IEEE 802.15.1 standard has been
modified to include many versions
To adapt to Arduino, it is best
implemented via a USB Host boards
that uses the Maxim 3421E chip that
has a uP matched interface
MAX3421E Chip
Notice the 3421 uses a SPI bus interface to the processor.
BlueTooth dongles are generally bases on a USB port.
The processor in interrupted. The handler reads the data
from the SPI bus.
Arduino and BT
Use one of the several USB Host
Shields (supports BT)
Watch that pins 11,12,13 will be
consumed by the SPI bus, which
could interfere with an additional
shield on top. Also, a SS pin must be
chosen. The board designers usual
use pin 10, which is also popular with
motor driver shields.
I chose to use a PS3 controller,
which has BT. A recent Library has
been made for the PS3 and the
latest USB Host Shields.
On top of this, I added a motor
controller shield and had to shift all
the control pins with a H/W mod to
avoid the SPI bus used by BT host.
SainSmart 4WD Cart
BT interface via USB Host Shield
Arduino Mega – so many I/O
connections
Ultra-sonic sensor for distance and
obstacle avoidance
Full H-bridge motor control based on
L298 chip
Servo breakout shield for sensor
servo and power distribution
Interrupts – real time control
Hardware sends signal
asynchronously
Sketch is set to react by halting code,
jumping to handler function, then
jumping back to next instruction in
normal flow of code
attachInterrupt(0,handler,RISING);
See pin-out diagram for interrupt pins
“handler” is a func you name
RISING is one of 5 signal sensing’s
Arduino Uno
int0 on pin 2, int1 on pin 3
Handler, or Interrupt Service Routine (ISR)
Void function with no return value
Can’t use delay() statement inside it
All variables used have to be typed “volatile” at
the top of sketch
LOW,HIGH,RISING,FALLING,CHANGE
Nothing in the sketch tells you about
interrupt accept the attachInterrupt() in the
set up function. When it comes, the ISR
just runs.
Precautions
The signal that triggers and interrupt
must be stable – no bounce or false
hits or the interrupt will trigger
multiple times
Best to use Real Time Clock or millis()
method for time delays or you could
miss an interrupt. Delay() blocks the
code while timing out.
Stepper Motors
Bipolar/Unipolar basically same in
function. Coils are split in the unipolar
Steps are done in a pattern to cog the
rotor between magnetic teeth in the
rotor and coils in the stator
Your can build your own controller or
use a shield
This demo uses Adafruit Motor Driver
to drive a scanner bed
How Stepper Work
The Arduino turns on the next pole to pull
the rotor and at the same time turns off
the lagging pole. This cogs the rotor to
the next step position.
Our demo of Steppers in Action
Stepper Motor
Drive belt
AF Motor Driver Shield
Motor Pwr
74HC595
Motor 1
H-bridge(x2)
Motor
phases
Let’s Combine Technologies
AdaFruit provides a Library to send
serial data to the shift register that
sets the control signals on the Hbridge and in quick secession, sends
the cogging or step pattern as well
The sled moves according to the
number of steps programmed
We’ll use sensors to find the end
points and interrupt the Arduino
Sensor set up:
As the sled goes left, the IR sensor sends a higher and higher
voltage. A comparator trip threshold is reached sending the
interrupt to the Arduino.
IR-sensor
(IR reflects off the sled)
Sled
trip blade
optical interrupter
As the sled goes right, the blade riding on the sled cuts through
the gap in the optical interrupter signaling the Arduino to stop
How an Optical Interrupter Works
When the gap is unblocked the photo-transistor conducts
and V+ is nearly 0V. V- is larger than V+, the output
goes LOW, because the output transistor on. When the
gap is block by the sled flag, the photo-transistor turns
off, and V+ nears 5V. This makes V+ larger than Vturning off the output transistor, and the output goes
HIGH.
4
5
Complex S/W solutions
Use functions to define jobs that are repeatedly used.
Use .h files to collect variable values that are program
defaults or pre-sets. This makes for one place to
make changes.
Take complex tasks and put them into a Class. Define
useful methods to use the Class
Interrupts are essential to real-time control that you
find in machine control – learn how to use them
Use a Real-Time Clock (RTC) to unload the processors
onboard clock, provide “watchdog timer” or time
stamp code output.
Use SD cards to store info – data logging
Learn how to design a scheduler into your code to
manage when a process starts and ends.
Wireless Comm
XBee – network style RF signal
Long range
2.4GHz freq
Series 1: serial interface
Series 2: complex mesh networking
Set via X-CTU HMI from
BlueTooth – Personal Area Network
Within 30 feet
Complex serial protocol, use Library
Door Bell
Layout
Not much to do here but send whether
button is pushed or not. The hardware
provides the ‘1’ or ‘0’
The main task is to read the serial
interface provided by the XBee
paired Transmitter/Receiver.
We’re using the millis() function here
to establish timing to cause the LEDs
to flicker and the tones to oscillate.