f-log

just another web log

28 Feb 2014:
flog archives updated for 2010,2011,2012 and 2013
Finally got around to updating the archives from 2010 through 2011, 2012 all the way to 2013

Actually quite amazing to see all the things I have done, and all the spelling and grammatical mistakes.
23 Feb 2014:
Does Blade Runner dream of electric sheep
In my quest to read all the things I think I should have already read I purchased "Do Androids Dream of Electric Sheep?"

It was ages ago that I last saw Blade Runner, but this book seems to take quite a different approach than the film. The first part of the book setting the scene and introducing the characters is good, the second part where the non-plot action is is good, but the last part is just weird. When I say "weird" what I mean is, deep. It gets quite religious and introspective. Not that that is a bad thing, it just does not follow the book so well.
The set pieces are all there and very vivid, a destitute Mars and time ravaged Earth, different classes of humans living varied lives.

I enjoyed the book and while reading it I lined up someone to lend it to, but with that last bit I am going to revisit if this sort of thing is really their thing.

Recommend if you are prepared for the humanity side of things, lots to think about.
18 Feb 2014:
Messed up my html table
opps messed up my table html there...
18 Feb 2014:
Load testing the stepper motor with 90p
I wanted to see what this little stepper motor was capable of, so I devised a "load test".
Stepper motor with plastic arm with hanging basket containing 1 pence coins
The arm is fashioned out of a plastic box lid and the basket is just a bottom 3rd of a salad cream bottle.
My first though was to use these buckycube magnets. Adding one at a time but I quickly added all of them and the motor happily rotated. Phase two was using one pence coins, plenty of those lying around.





#coins weight slips notes
50 178g NO
75 267g YES Slips only when running counter clockwise
90 320.4g YES Slips in both rotations

Which is really quite impressive for such a small motor.

FYI 1 pence weighs 3.56g [source].

and I have no idea why the best performance was clockwise.
11 Feb 2014:
raspberry pi is stepping up
In amongst the stuff I got from Amazon was stepper motor and an LCD panel. I have not looked at the LCD panel yet so its time to dig into the stepper motor.

I went for the cheapest option at £3.21 28BYJ-48 28BYJ48 DC 5V 4-Phase 5-Wire Arduino Stepper Motor with ULN2003 Driver Board

Stepper motors are quite simple once you have them working but with no idea what I was doing I was very happy to find a number of Pi enthusiast had been there before.

Main tutorial I followed
more hardcore, glad I did not need
yet another
alternative driver board
cheap driver board kit for two motors

Each tutorial author had decided on a different set of GPIO pins but this one had them all nicely grouped at one end. See my build photo at the end of this post.

I spent some time with this tutorial trying to get all the pins correct. But when I ran the python code the motor did not turn, strangely the LEDs turned on and off in sequence. The four LEDs light when the four electro magnets are enabled, wikipedia explains with a nice animation.

Fearing the worst I turned to stackoverflow where someone else had experienced the same(?) problem. Their main culprit was the power supply.

Just about to bin the whole thing as "cheap rubbish" I picked up the motor while the code was running. To my surprise the metal cylinder had a heartbeat. A small vibration each time the LEDs changed, which was every half a second. Intrigued, I started to dig more into stepper motors and found I could almost imperceptibly feel the motor ever so slowly ticking round.

By changing the delay in the code I could make the motor turn faster. At a 0.001 delay the motor whizzed round in 8.5 seconds. But it would sometimes get stuck.

In the code was an alternate pattern for calling the outputs, labelled "manufacturers datasheet". Changing to this greatly improved the reliability and I had no more "stalls"

I set about trying to find out how many "steps" were required to complete a 360 degree revolution. I found I had to change my delay from 0.001 to 0.01 or it would seem to skip steps and create non-reproducible actions. The first value 100 moved the arm hardly at all, the second 1000 seemed to be an exact quarter, but 4000 was not quite a full circuit.

Trial and error lead me to 4100 and I found I could run my code repeating 4100 steps clockwise and then 4100 steps counter clockwise over and over again (main test was eight times) and the arm would always end up in the exact same place. It turns out that the 4100 figure is because the motor has 64 ratio gearing and if you want to get technical the correct value is 4100.22.

#-----------------------------------
# Name: Step.py
#
# Author: Rob Davis
# Based on the Stepper Motor code from matt.hawkins www.raspberrypi-spy.co.uk/2012/07/stepper-motor-control-in-python/
#
# Created: 2014/02/09
#
# Takes parameters for number of steps and which direction from the command line.
# e.g.
# sudo python step.py 4100 CCW
# To operate the motor for 4100 steps (a complete revolution) in a counter clockwise direction.
#-----------------------------------
#!/usr/bin/env python

import sys
import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

# Define GPIO signals to use
# Pins 18,22,24,26
# GPIO24,GPIO25,GPIO8,GPIO7
StepPins = [24,25,8,7] # CW rotation
if (sys.argv[2]=="CCW") :
StepPins = [7,8,25,24] # CCW rotation

# Set all pins as output
for pin in StepPins:
GPIO.setup(pin,GPIO.OUT)
GPIO.output(pin, False)

# Define some settings
StepCounter = 0
WaitTime = 0.01

# Define simple sequence (do not use)
StepCount1 = 4
Seq1 = []
Seq1 = range(0, StepCount1)
Seq1[0] = [1,0,0,0]
Seq1[1] = [0,1,0,0]
Seq1[2] = [0,0,1,0]
Seq1[3] = [0,0,0,1]

# Define advanced sequence as shown in manufacturers datasheet
StepCount2 = 8
Seq2 = []
Seq2 = range(0, StepCount2)
Seq2[0] = [1,0,0,0]
Seq2[1] = [1,1,0,0]
Seq2[2] = [0,1,0,0]
Seq2[3] = [0,1,1,0]
Seq2[4] = [0,0,1,0]
Seq2[5] = [0,0,1,1]
Seq2[6] = [0,0,0,1]
Seq2[7] = [1,0,0,1]

Seq = Seq2
StepCount = StepCount2

# Start main loop
steps = int(sys.argv[1])
stepc = 0
while stepc<=steps:
print "Step %i of %i" %(stepc,steps)

for pin in range(0, 4):
    xpin = StepPins[pin]
    if Seq[StepCounter][pin]!=0:
     GPIO.output(xpin, True)
    else:
     GPIO.output(xpin, False)

StepCounter += 1

# If we reach the end of the sequence start again
if (StepCounter==StepCount):
    StepCounter = 0
if (StepCounter<0):
    StepCounter = StepCount

# Delay to allow electro magnets to align the gear wheel
time.sleep(WaitTime)
stepc+=1


You can see the Pi wired up with my cobbler, a bread board and the stepper motor driver.
The arm was a piece of plastic toy I found in the bin. It has bit of cardboard wedged in the hole to keep it tight.
28BYJ-48 28BYJ48 DC 5V 4-Phase 5-Wire Stepper Motor with ULN2003 Driver Board wired up to a Raspberry Pi via a cobbler breakout board
Here is a close up of the wiring.
28BYJ-48 28BYJ48 DC 5V 4-Phase 5-Wire Stepper Motor with ULN2003 Driver Board wired up to a Raspberry Pi via a cobbler breakout board close up of wiring


08 Feb 2014:
Making the Pi listen to the Daffodil
This USB soundcard was only £4.25 but I have wanted to try voice stuff with the Raspberry Pi for a bit and as I had a Amazon gift card, it was purchased with a load of other "stuff".
Photographs of a USB sound card from three angles.
Got it working very quickly.
Plug it in
Detected
dmesg
[2504032.732583] usb 1-1.2: new full-speed USB device number 4 using dwc_otg
[2504032.837909] usb 1-1.2: New USB device found, idVendor=0d8c, idProduct=000c
[2504032.837941] usb 1-1.2: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[2504032.837961] usb 1-1.2: Product: C-Media USB Headphone Set
[2504032.852884] input: C-Media USB Headphone Set as /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2:1.3/input/input0
[2504032.853327] hid-generic 0003:0D8C:000C.0001: input,hidraw0: USB HID v1.00 Device [C-Media USB Headphone Set ] on usb-bcm2708_usb-1.2/input3
[2504033.096745] usbcore: registered new interface driver snd-usb-audio


lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0d8c:000c C-Media Electronics, Inc. Audio Adapter


Set levels
alsamixer -c 1
That's for Card 1, as apposed to Card 0(default). Controls in alsamixer are arrow keys, 'M' and 'ESC'.

Find device
aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
sysdefault:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
default:CARD=Set
    C-Media USB Headphone Set, USB Audio
    Default Audio Device
sysdefault:CARD=Set
    C-Media USB Headphone Set, USB Audio
    Default Audio Device
front:CARD=Set,DEV=0
    C-Media USB Headphone Set, USB Audio
    Front speakers
surround40:CARD=Set,DEV=0
    C-Media USB Headphone Set, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Set,DEV=0
    C-Media USB Headphone Set, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Set,DEV=0
    C-Media USB Headphone Set, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Set,DEV=0
    C-Media USB Headphone Set, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Set,DEV=0
    C-Media USB Headphone Set, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Set,DEV=0
    C-Media USB Headphone Set, USB Audio
    IEC958 (S/PDIF) Digital Audio Output


Record
arecord -D "default:CARD=Set" file
Recording WAVE 'file' : Unsigned 8 bit, Rate 8000 Hz, Mono

But note the
Unsigned 8 bit, Rate 8000 Hz, Mono
This produces VERY noisy, crackly results.
Setting the format to the be CD quality
arecord -f cd -D "default:CARD=Set" file
Produces a much smoother/cleaner result.

Playback
aplay -D "default:CARD=Set" file

There are lots of examples of what to edit to make the USB card the default. I much prefer having the commands to use it when I want.
loading results, please wait loading animateloading animateloading animate
[More tags]
rss feed

email

root

flog archives


Disclaimer:
This page is by me for me, if you are not me then please be aware of the following
I am not responsible for anything that works or does not work including files and pages made available at www.jumpstation.co.uk I am also not responsible for any information(or what you or others do with it) available at www.jumpstation.co.uk
In fact I'm not responsible for anything ever, so there!

[Pay4Foss banner long]