[ Chrome crashed and I now have to try and replicate what I had said]
This is what I am going to try and do: http://www.instructables.com/id/IoT-Controlling-a-Raspberry-Pi-Robot-Over-Internet/
It's using basic apps and should be quite versatile.
It is version #6 for me.
I am using SD card #1 and have started with Raspbian stretch, loaded the network wireless interface configurations that I use and the empty ssh file in the root directory.
Connected via ssh and
sudo raspi-config to expand file space
sudo apt-get update
Then needed 'git' so sudo apt-get install git.
From the instructables installed wiringPi:
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
Now to figure out how to initialise the output pins at startup. The pins that I have used before are:
FORWARD = 17 # GPIO pin using BCM numbering
BACKWARD = 23
STOPPIT = 25
LEFT = 10
RIGHT = 11
just to test I did:
pi@raspberrypi:~ $ gpio -g mode 10 out
pi@raspberrypi:~ $ gpio -g write 10 1
pi@raspberrypi:~ $
pi@raspberrypi:~ $ gpio -g write 10 0
pi@raspberrypi:~ $
which worked.
pi@raspberrypi:~ $ gpio -g write 10 1
pi@raspberrypi:~ $
pi@raspberrypi:~ $ gpio -g write 10 0
pi@raspberrypi:~ $
which worked.
My script will be a bit simpler than the example because forward/reverse are a mating pair and left/right are also.
Script 'forward' will be:
#!/bin/bash
gpio -g write 17 1
gpio -g write 23 0
and 'stop' will reset everything
#!/bin/bash
gpio -g write 10 0
gpio -g write 11 0
gpio -g write 17 0
gpio -g write 23 0
these scripts go into /var/www/cgi-bin and get set to chmod 755
wrote initialisation commands into /etc/rc.local
gpio -g mode 10 out
gpio -g mode 11 out
gpio -g mode 17 out
gpio -g mode 23 out
that's completed step 3.
Jump to step 5. Installing the web server.
done, and also step 6 started, Have copied html to PC and now need to edit it and find button images to store on RPi.
[2017-11-28] Going to nick button images from one of the early attempts and use them.
No I'm not. They are gone.
Downloaded an arrow png and saved three more copies of it rotated 90 deg each time. Also a red Stop cross. Ftp'd down to var/www/images
Moved index.html to /var/www.
stopped and started lighttpd. but when I browse to it, it displays the html code?
Chmod 755 the index.html, but still no success.
Commented out the commands and it works using the script from the writeup. Now need to take out some bits and move on.
Then to try it on the car and not just on the test breadboard.
Note: one problem that I know that I am going to have is doing turns. On the previous WebIOPi version I initially touched teh button a second time to stop the action, then modified the program to only turn for 300ms then switch off the turn and return to centre. Need to figure out whether I can do this in the bash scripts here.
[2017/11/30]
In one of the WiringPi blogs I noticed that I have to initialise the GPIO for pwm using this string "export WIRINGPI_GPIOMEM=1" so I did, but no effect.
WiringPi at: http://wiringpi.com/
WiringPi at: http://wiringpi.com/
[2017/12/01]
Just rewired the test rig so that reverse (on pin 23) now on GPIO18 /wiringPi 1, Pin 12 and tested with the scripts in the article. That works because it is the hardware pwm pin.
To make it work on the car I am going to have to rewire the forward pin (17) to this location. If I wanted to do it for both forward and reverse I would need a NAND gate on each. One input to select the direction and one to select the speed/pwm.
Also I would have to figure out where to initialise the pwm pin. can I do it in the rc.local initialisation, or run a script from the html at startup.
[2017-12-02]
Changing the pin for the Forward motion also requires going back to the other working version (WebIOPi) and changing that so that both programs are compatible with the same hardware without changes. I'll do it though just so that I can play with pwm.
In WebIOPi I have to change all three files- Config, Index.html, and script.py
This works ok in car. I must make the changes to the file on the PC to keep in step.
BUT the Instructables version only works for Left/right., not forward and backwards, and I have just realised why. I didn't initialise in rc.local the pin 18.
Done that, but not working. More thinking required.
[2017-12-03] Rewired test rig of LEDs to tidy up.
Tested with WebIOPi system to check it still all works, with forward on pin GPIO 18
Instructables version - Forward works, reverse doesn't and pwm controls do not.
Note this one is now on IP ...9. It means I don't have to reset the SSH security every time I log in to a different system.
In the regularspeed.cgi script I set the pin 23 to 0 before the pwm statement. - No effect.
[2017-12-04] Just a thought that pin 18 cannot have dual modes of operation. Can only be logic0/1 or pwm. This gives a problem when going in reverse, as I am not sure how to set it to a zero state. Acknowledging that if I keep pin 18 as pwm, then going in reverse will have the opposite effect, i.e full speed will = nospeed and vice versa.
worth a play, I'll edit the forward and backwards.cgi scripts.
rc.local:
gpio -g mode 10 out gpio -g mode 11 out gpio -g mode 18 pwm gpio -g mode 23 out
I think that I have to accept that Reverse doesn't work, when pwm on pin 18 and pin 23 is set high.
Tested on the car, and the motor only seems to have one speed in forward. Reverse still doesn't work. I think that the relays do not react fast enough to be able to support pwm.
A discussion with friends at the Dorset LUG made me realise that pin 18 (pwm) is only a source, not a sink, so obviously the motor would not go in reverse. Also they confirmed that I cannot drive relays with pwm, If I want that to work I should swap,out the relays for thyristors.
End of story until I find another IoT program to try!
[2018-02-08] Unfortunately something has disturbed the circuitry on the car, and now the steering doesn't work. I have decided to retire it until I get another car from the tip. Might be awhile.
[2017-12-04] Just a thought that pin 18 cannot have dual modes of operation. Can only be logic0/1 or pwm. This gives a problem when going in reverse, as I am not sure how to set it to a zero state. Acknowledging that if I keep pin 18 as pwm, then going in reverse will have the opposite effect, i.e full speed will = nospeed and vice versa.
worth a play, I'll edit the forward and backwards.cgi scripts.
rc.local:
gpio -g mode 10 out gpio -g mode 11 out gpio -g mode 18 pwm gpio -g mode 23 out
I think that I have to accept that Reverse doesn't work, when pwm on pin 18 and pin 23 is set high.
Tested on the car, and the motor only seems to have one speed in forward. Reverse still doesn't work. I think that the relays do not react fast enough to be able to support pwm.
A discussion with friends at the Dorset LUG made me realise that pin 18 (pwm) is only a source, not a sink, so obviously the motor would not go in reverse. Also they confirmed that I cannot drive relays with pwm, If I want that to work I should swap,out the relays for thyristors.
End of story until I find another IoT program to try!
[2018-02-08] Unfortunately something has disturbed the circuitry on the car, and now the steering doesn't work. I have decided to retire it until I get another car from the tip. Might be awhile.
No comments:
Post a Comment