Week 8 in ScratchPiBot Club
Eureka! We have 2 ‘bots that can follow a line for 3 metres!
The boys managed to get theirs to do it first as myself and the girls were embarking on raising the height of their ‘bots IR Sensors as when they got too close to the ground – they gave faulty line detection results.
Once we done this (and made our turning strategy quite aggressive!) the girls ‘bot zig-zagged its way down their track as well.
Boys Code | Girls Code |
![]() |
![]() |
So we should be ready to have a set of races next week and see who can push their ‘bot the fastest without losing its way.
As not everyone can be programming the computers at the same time, the other club members have grabbed some flip cams and started filming the runs so hopefully we will have some video to show you next week.
Simon, if you release the SPI pins you can do ‘proper’ a to d from scratch with an mcp3002/8 chip.
# Scratch client test program
from array import array
import spidev
import time
import os
import RPi.GPIO as GPIO
import eeml
GPIO.setmode(GPIO.BCM)
import socket
HOST = ‘127.0.0.1’
PORT = 42001
spi = spidev.SpiDev()
spi.open(0,0)
def readadc(adcnum):
r = spi.xfer2([1,(8+adcnum)<<4,0])
got_it = ((r[1]&3) << 8) + r[2]
return got_it
def work_out(adcnum):
got_it = 0
a = 0
while a > 24) & 0xFF))
a.append(chr((n >> 16) & 0xFF))
a.append(chr((n >> 8) & 0xFF))
a.append(chr(n & 0xFF))
scratchSock.send(a.tostring() + cmd)
print(“connecting…”)
scratchSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
scratchSock.connect((HOST, PORT))
print(“connected”)
while 1:
i = work_out(0)
data = scratchSock.recv(1024)
if not data: break
if “temperature” in data:
sendScratchCommand(‘sensor-update temperature ‘ + str(i))
print(data)
else:
print(“failed”)
time.sleep(0.5)
print(“closing socket…”)
scratchSock.close()
print(“done”)