Sunday, 26 January 2020

RC Car Steering with PWM and more about Servos

At the end of https://madsmaddad.blogspot.com/2019/07/rc-car-number-3.html I mentioned that I was going to try this. I said that I had binned CAr #2, but it was actually car #1, and #2 was in a box hidden away. This post is about car #2.

After proving that I could use a Raspberry Pi to drive a Servo, I decided to change out the motor drive steering of this car for a servo and adjust the software accordingly to drive it.   The initial video that explained it all was at https://www.youtube.com/watch?v=N5QmZ92uvUo and he explains teh concepts behind PWM control with it. A simpler explanation is at https://www.youtube.com/watch?v=xHDT4CwjUQE

I have got it working but have not yet taken it out on the road because the R-Pi is sitting beside the car like a heart monitor.


Here is the servo in position for steering car I drilled a hole in the steering arm for the servo arm to go through, rather than trying anything fancy like rods as usually seen in RC airplane controls.  The Servo is stuck in place courtesy of my hot glue gun. At the top right of the picture is the original steering motor just pushed out of place. 



Raspberry Pi Model B connected to the Car. All of the pins connected to the second row of the GPIO except for a yellow ground pin.
Pin 2  +5v to Servo Black wire
Pin 6   gnd to Servo Reddish wire
pin 12 to  IC socket pin 11
Pin 16 to IC socket pin 10
Pin 18  PWM to Servo Yellow wire
Pin 9   gnd to IC socket pin 2 (gnd)

See this previous writeup for the IC pinouts on the control board. https://madsmaddad.blogspot.com/2018/03/second-rc-car.html




This shows the IC socket replacing the receiver IC on the driver board. The black connector card connects all the driver outputs to the relevant motor and also brings in the power for the board from the battery pack at the bottom of the picture.

SOFTWARE

This uses  the Flask setup with the Wifi setup as an Access Point so that I can work direct to it from my tablet.

There are three programs required.

Shell script:  Incorporate this in rc.local to make it run at startup,
export FLASK_APP=/home/pi/rc-car/app.py
flask run --host=192.168.1.8

Set IP address to correct address for the Access Point setup.

HTML:

<!DOCTYPE html>

<! developed using https://www.w3schools.com/css/css_grid.asp for the grid 30 Jan2019

<html>
<head>
<title>RC-Car with Flask & PWM steering 20-1-2020</title>
<style>
.grid-container {
  display: grid;
  grid-template-columns: auto auto auto auto;
  background-color: #ffffff;
  padding: 10px;
  grid-column-gap: 20px;
  grid-row-gap: 50px;
}
.grid-item {
  background-color: rgba(255, 255, 255, 0.8);
  border: 3px solid rgba(0, 0, 0, 0.8);
  padding: 20px;
  font-size: 50px;
  text-align: center;
}
</style>
</head>
<body>

<h1 align="center">RC-Car with Flask & PWM 20-1-2020</h1>


<div class="grid-container">
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item">
    <a href="/motor-forwards/" data-toggle="tooltip" title="Forward" class="btn btn-success">Forward</a>
    </div>
   <div class="grid-item"></div>

  <div class="grid-item">
    <a href="/motor-left/" data-toggle="tooltip" title="Left-Left-Left!" class="btn btn-success">Turn Left</a>
    </div>
    <div class="grid-item">
    <a href="/turn-center/" data-toggle="tooltip" title="Left-Left-Left!" class="btn btn-success">Center</a>
    </div>
  <div class="grid-item">
    <a href="/motor-stop/" data-toggle="tooltip" title="Stop Motors"  class="btn btn-danger">STOP</a>
    </div>
  <div class="grid-item">
     <a href="/motor-right/" data-toggle="tooltip" title="Turn right!" class="btn btn-success">Turn Right</a>
    </div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item">
    <a href="/motor-backwards/" data-toggle="tooltip" title="Reverse!"  class="btn btn-warning">Backward</a>
    </div>
  <div class="grid-item"></div>
</div>

</body>
</html>


Note that I have used W3Schools for a lot of help in getting my HTML correct. Some of the bits in each line referencing the contents of a box are possibly redundant. They were there in the code where I pinched the stuff.  [ see below for simplified stuff].

PYTHON:

# 2020-1-20 Modifications to drive steering using a servo and PWM.  Because I
# don't know if gpiozero and RPi.GPIO can work together I'll remove the GPIOzero and motor
# command.  motor = Motor(forward=12, backward=16)
# look at ancient code for motor handling.
#  2018-04-05 Modified from Les Pounder program to handle two motors
# one for steering and one for motion
# steering is Left = 10, right = 11
# changing it trying to add Turn for motor control
# 2018-10-31 changing toggle LED to stop motors

from flask import Flask, render_template
from time import sleep
import RPi.GPIO as GPIO

#Set GPIO Numbering mode

GPIO.setmode(GPIO.BOARD)

# set pins for motor control

GPIO.setup(12,GPIO.OUT)
GPIO.setup(16,GPIO.OUT)

# set pin 18 as Output for Servo Steering
GPIO.setup(18,GPIO.OUT)
servo_st = GPIO.PWM(18,50)

#start PWM running on servo, init value 0 (pulse off)
servo_st.start(0)
# servo runs from duty cycle 2 to duty cycle 12, 7 being central position  for servo used in youtube demo.
# define variable duty
duty = 2

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/motor-stop/')
def on():
    GPIO.output(12,False)
    GPIO.output(16,False)
    return render_template('index.html')

@app.route('/motor-forwards/')
def motorforwards():
    GPIO.output(12,True)
    GPIO.output(16,False)
    return render_template('index.html')

@app.route('/motor-backwards/')
def motorbackwards():
    GPIO.output(12,False)
    GPIO.output(16,True)
    return render_template('index.html')

@app.route('/motor-left/')
def motorleft():
    duty = 2
    servo_st.start(duty)
    sleep(1.3)
    servo_st.ChangeDutyCycle(0)
    return render_template('index.html')

@app.route('/turn-center/')
def centersteering():
    duty = 7
    servo_st.start(duty)
    sleep(0.3)
    servo_st.ChangeDutyCycle(0)
    return render_template('index.html')

@app.route('/motor-right/')
def motorright():
    duty = 15
    servo_st.start(duty)
    sleep(0.3)
    servo_st.ChangeDutyCycle(0)
    return render_template('index.html')

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')


The major changes in this, other than PWM operation, is the change to GPIO Board numbering rather than GPIO Name numbering.  Also I stopped using GPIOzero, so have reverted to direct control of pins in the software. I like this better. Comments can be used to explain functions that are not clear.


Questions: I am happy to answer them, but they may be already answered in previous posts.

27/1/2020  corrections and simplifications
The  line
 <a href="/motor-forwards/" data-toggle="tooltip" title="Forward" class="btn btn-success">Forward</a>

can be simplified by removing things that don't serve any purpose in this case. It becomes:
 <a href="/motor-forwards/" >Forward</a>


SERVOS

I was given a box of Servos and after having problems with the one that I had put in the car, I went through them plugging them into the Raspberry Pi.

Four of them totally didn't work and caused the R-Pi to shut down.  These were all small ones without labels.

Some of them partially worked.

Here is a breakdown of what happened. The software is set to duty cycle 2 for a Left turn, 7 for a centre position, and 15 for a right turn. I noticed that in some cases the servo shaft turned CCW when I expected CW, and am now confused as to which is left and right.

Device                                               Left               Centre           Right
small unit with black arm.                   x                     ?                    ?

Small unit with white arm                  -90                    0                 +90 (CW)

Digifleet FPS-20                                 -60                    0                 +60

Digifleet FPS-30   dead kills Pi.

Aristocraft HS-100                            -90                increments              increments
'increments' possibly means that I have to extend the range. needs testing

GWS Mini STD                                +90                    0                  -90

Tower Pro Airplane 99                            iffy, slow to respond

Small Black with arm                       +110             no response         -100

Black, short wires                            +110                                          -90

Digifleet FPS33 (2)       dead

Black with black arm.           dead

Powermax Skyranger 5 white-X arm      +75                steps                           -70

Steps/increments probably means that I have to expand the range from 2-7-15.

Another bothersome feature of these servos is that the arms, or whatever the proper term for them is, are different sizes and shapes so are not transferrable from one unit to another. Most are splined, but some are square.

2020-02-08  See https://en.wikipedia.org/wiki/Servo_control

It is not duty cycle that is important, it is pulse width, generally between 1msec to 2 msec wide.
Now I am using a value of duty 2-7-12  with a pulse rate of 50 Hertz.


Also:
https://learn.adafruit.com/adafruit-raspberry-pi-lesson-9-controlling-a-dc-motor/software

and

https://github.com/sarfata/pi-blaster








Tuesday, 14 January 2020

resolving Humax 9150T PVR problems

Initial status  Pre-November 2019
UPSTAIRS
PVR1 sn=...00617                      HD = ...4390
DOWNSTAIRS
PVR2 sn=...01135                      HD = ...0465
------------

22/11 Swapped HD's
- Schedule went with PVR, not HD
- channels selected with PVR, not HD

20/12
 Downstairs  00617 PVR with 0465 disk
HW  Rev 1.0
S/W  1.00.26
Loader  a4.39
Sys ID 3024.0000

UPSTAIRS  01135 PVR 4390 disk
HW  Rev 1.0
S/W  1.00.26
Loader  a4.37      *** only difference
Sys ID 3024.0000

--------------
Skipping occurs on downstairs PVR Now
but only on recently recorded items
Skipping no longer occuring Upstairs.
Skipping defined as playback jumping forward nearly a minute. able to play 'jumped' part if  I rewind to just after the skip started.  The skip is repeateable at the same point always. It seems to occur randomly in the things recorded.

Hypothesis: It is the recording on PVR 00617 that lays down the condition that causes the skip to occur.

What I may do is test whether I can view recording pulled up to PC on my tablet and if so, swap DOWNSTAIRS HD for the spare one that I have.  15-1-20 Can play recording  on tablet.

15-1-20  UPSTAIRS skipping occured once on 1hr program at about min 56

Dug out other HD sn ....6920






Wednesday, 4 December 2019

Raspberry Pi to replace DVR

As our Humax 9150T DVRs are exhibiting some funny characterisitics, I thought that I would see what I could do with my Raspberry Pi. At the DLUG computer club the other night, Kodi was suggested as probably the best software for this. https://kodi.wiki/view/HOW-TO:Install_Kodi_on_Raspberry_Pi

Ia getting together the bits. I was going to use my 160GB Sata Hard disk, but I don't have a USB converter for it.  I am going to use a 40GB IDE disk with my IDE to USB converter. I have my freecom DVB TV stick if that can be used, and the R-Pi bodel B is available, or maybe the Pi-zeroW. I have a seven port USB hub which may be up to the job - That we will see.

Step one - download the software and get it working.
Initially it wouldn't connect by Ethernet, so I started it on WiFi and it connected. I have updated and upgraded the Raspian Buster system, and now am installing Kodi.

Have attached 40G IDE disk via USB, and restarted R-Pi.

From Kodi Wiki page, I cannot find if I can run Kodi via SSH. It seems to want a big screen and a remote control for all operations.

It's not simple - I can't be bothered.




Sunday, 15 September 2019

Upgrading an Android OS

My Argos Bush android tablet is running Android 6.0  which is Build Number MRA58K@ARCHOS.20160617.013735.Catalpa.

I have recently tried to install a couple of Apps and been told that they were not compatible with my tablet.

Can I rebuild a later Android OS for my tablet?                                                   15/9/2019

The Archos site is no use: https://www.archos.com/gb/support/downloads.html?type=tab

https://www.androidauthority.com/build-custom-android-rom-720453/
The two things that I would need help obtaining:
Grab the source – This is an easy step, however it takes a long time. For me it took over 24 hours. Such a large download only happens once, further syncing with the main source tree will be incremental.
Obtain proprietary binaries – The binary drivers should be unpacked in your working directory.


https://www.youtube.com/watch?v=99LUjX63LhU

https://www.youtube.com/watch?v=1pAr5VzpxyY

17/9/19 emailed Archos:
This Android Tablet is running Android 6.0 and I am now finding Apps that won't run on it. How can I upgrade it to a higher version of Android?
I am happy to try and build the OS myself if given the source and binaries neede, and possibly some instruction.

This would lead to the question - How to export/backup the current OS before attempting any updates, in case of failure.

Thank You, Peter Merchant

21/9/19 No response from them yet, but look what I found:
https://source.android.com/
This will be quite a learning experience

2/10/19 Suggestion from LUG www.xda-developers.com  which is on topic but only seems to cater for popular devices.



Saturday, 14 September 2019

Build your own Electric car

If I wanted to build my own car, real not toy,  where would I start?
What components would I need? I would probably like to start with an old mini, because it is small and light.

Recently I have seen this  new motor design:
https://www.youtube.com/watch?v=8gO60bt6rqk&feature=youtu.be

But in the past I saw a mini with individual motors in each wheel which I liked.
https://www.treehugger.com/cars/electric-mini-0-60-in-4-seconds-it-has-motors-in-its-wheels.html
It might have used these:
https://www.proteanelectric.com/


You need power for the motors, and a power control system,. You also need all sorts of computers to feed information to the driver, look after safety details, and react to the driver to perform operations on the car, such as signalling. Do these computers need a seperate power source?

As with anything you also need a braking system.

More thoughts to be posted as they arrive, and then I'll sort them and rewrite this.

Other people have already done this:
https://www.instructables.com/id/Build-your-own-Electric-Car/

https://www.designboom.com/technology/low-cost-diy-electric-car-made-from-recycled-parts-380-mile-range-06-17-2017/

25/10/2019 On BBC. It mentions Protean (above)
https://www.bbc.co.uk/news/business-49958457






Saturday, 31 August 2019

Preparing SD cards for Raspberry Pi

Step by Step instructions on how I do it.

First use Etcher to download the program to the SD card.  Today this is Raspbian Buster.

Use the browser to connect to the Boot partition of the SD card and create an empty file called 'ssh'

Now plug the SD card into the R-Pi and power it on. Connect via Ethernet. Use a utility like fing on a tablet to determine the IP address.

We need to configure networking. I have three files on my PC that are copies of the networking files from the R-Pi that are set up the way that I like them. I use a fixed wireless and a fixed Wired ethernet address on my devices.

The IP address found by fing is 192.168.1.22.  In a terminal, use ssh to connect to the R-Pi.
ssh  -l pi 192.168.1.22.  I always have to reset keygen when I am operating on a different IP address here.

cd ..
cd ..
cd etc
sudo nano dhcpcd.conf  and toward the end of the file add the lines:
# Example static IP configuration:
interface eth0
static ip_address=192.168.1.9/27
static routers=192.168.1.1
static domain_name_servers=192.168.011 8.8.8.8

interface wlan0
static ip_address=192.168.1.8/27
static routers=192.168.1.1
static domain_name_servers=192.168.1.1  8.8.8.8

This may vary depending on your network and Sub-network mask. 

Comment out the line "slaac private"
CTRL o to write file and CTRL x to exit

cd wpa_supplicant
sudo nano wpa_supplicant.conf
change this file to be:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

network={
ssid="bmth-wireless"
psk="3C0M5PGM"
# proto=RSN
key_mgmt=WPA-PSK
# pairwise=TKIP
# auth_alg=OPEN
}

Save and exit
Don't forget to change the ESSID and PSK to your own values.

I had to change the properties of this file so that it was accessible.
sudo chmod 777 wpa_supplicant.conf.

Now other  Raspberry pi preparations and setup
Use sudo raspi-config to expand the file system (Under advanced settings).
sudo apt-get update

At this point I reboot to get the new IP addresses. You will need to ssh in again.

sudo apt-get install python3-flask.
mkdir rc-car
cd rc-car
mkdir templates
save app.py in the rc-car directory
save index.html in the templates directory


sudo apt install python3-gpiozero

Use filezilla and transfer files to the Pi  or copy and paste contents of files using nano.

Need a script file to start Flask. It is in the /pi directory    go-car.scr
It is:
export FLASK_APP=/home/pi/rc-car/app.py
flask run –host=192.168.1.8

sudo chmod 777 go-car.scr   to make it executable. 

Also edit /etc/rc.local and add these two lines to it.

Setting up Ad-Hoc networking:
sudo apt-get install dnsmasq hostapd    --> done


stopped dnsmasq and hostapd, and rebooted. 

got as far as installing and shutdown instead of reboot.
Changed wireless SSID to 'rc-car' and WPA to 'Ashmeads'
IP range is dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
Edit /etc/dnsmasq.conf to contain
interface=wlan0
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
If Wireless doesn't work, it is because the firmware is not installed:

sudo apt-get install firmware-zd1211










Sunday, 18 August 2019

8mm Film digitising

For a long time I have wanted to see what was on the two 8mm films that I have. On friday 16th August I bought a Bell and Howell 635 Moviemaster projector at the market. I haev brought it home and lubricated it, and got it working. I lost the cheat sheet showing how to thread the film when I packed it up at the market, but I have found it here:
http://www.acexie.com/bell-howell-model-635-projector/

I have picked up the manual from here though:
https://memoriesofrxmp.info/wp-content/uploads/2017/09/Product-Brochure-BH-635.pdf

It is now downloaded.

Now I think that I have heard that you have to sync the frames palying with the frames being recorded on the digital camera. That's the enxt investigateion.