Monday 27 November 2017

RC-Car-5 Control from Instructables

This looks like a good solution because it just uses common applications and is not someones proprietary do it all app. I did like the idea of the Scratch like interface in Wyliodrin, but am quite happy to write code when I can see what I am doing.

[ 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. 
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/


[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.




















































Saturday 18 November 2017

RC-Car-4 WebIOPi is Obsolete. Long live ??

WebIOPi does not work with the latest version (stretch) of Raspbian.                            [2017-11-18]

My current state of memory cards is:
#1 SD card  not known
#2 SD card  Raspbian Jessie with WebIOPi not working
#3 uSD card WebIOPi working  - DO NOT TOUCH!
#4 uSD card WebIOPi working  - DO NOT TOUCH!  in RC-Car

#5 according to my records, is Forth, but I can't find it.

The Raspberry Pi that I am using for test purposes is a Model B rev 1, that accepts SD cards. If I want to do anything on my Raspberry Pi zero I am going to need some more uSD cards.

Cayenne is only supported on Raspbian wheezy according to the forums. And someone else on the Raspberry pi forums commented that it required cloud access, which is not something we want.

Blynk  As from previous post, does not work on my Raspberry Pi model B rev 1.

so what is next?

OOOh! Look what I found:
https://kaazing.com/remote-controlling-a-car-over-the-web-ingredients-smartphone-websocket-and-raspberry-pi/

Let's give it a try.  No. The detail isn't there, and it needs a Web-socket server 3rd piece of kit.

Next:


https://www.hackster.io/user16288277/diy-smart-iot-control-panel-raspberry-pi-zero-w-6d7264

This one uses a Mosquitto MSQT Message broker. May be smarter than I need.



Going to try the last one. 

Flashed the SD card #1 

Edited interfaces file to set static IP for wireless
Interfaces file refers to /etc/wyliodrin/wireless.conf, but no information is given about how to set this up. I could change back to wpa_supplicant, or wait for a response from wyliodrin.

Added ssh file in boot.
Added new project to Bookmarks bar.

[2017-11-23] Wyliodrin responded, said to put json file in the root of the FAT of the SD card. I have done this with no effect. I have loaded up Wyliodrin Studio and am trying to connect via Ethernet, but nothing is happening. It is, but it wants a username and password, neither of which are setup on the pi.
 Blank   blank doesn't work
blank   raspberry doesn't work
root    raspberry   doesn't work
peter.merchant_peter_merchant@wyliodrin.com  doguxokefu   doesn't work - from json file.

pi    raspberry is the correct set as per the default for the R-pi. (STUPID!)

[2017-11-26]   It didn't work, it wanted to update and hung. Wyliodrin suggested I use a later version linked to from Wyliodrin Studio, so I downloaded version 2017_08_25. This fired up, W-Studio connected to it, then said it couldn't find Wyliodrin and did I want to download it, which failed. I am not impressed so far.

I am going to prepare SD card #2, and see if that works.
Answer: No. Wyliodrin Studio tells me that Wyliodrin is not installed on the Pi that it is connected to.

I may wait and try this again sometime. Meanwhile on to the first one (Instructables) tomorrow.





Thursday 9 November 2017

RC-Car-3 The fun is in the making, not the using.

I have always wanted to play with RC vehicles, but never wanted to spend the money on the finished product, thinking that I would be bored with it in five minutes.

The Raspberry Pi gives everybody the opportunity to build things, and I decided to build an RC car for starters, but again, I thought that buying the appropriate parts and putting them together would take a lot of the fun out of it, so I decided to see what I could do with the R-Pi and a defunct RC car that I picked up at the tip. This story is told  in my blog: http://madsmaddad.blogspot.co.uk/2016/04/raspberry-pi-to-drive-ex-rc-car.html

I keep on looking at what has been done by others, but I am not going to just follow their instructions.  A quick google:
http://www.instructables.com/id/Raspberry-Pi-Smartphone-Controlled-Rc-Car/  - Looks like I might have to learn some Javascript, and I don't want to.

https://www.raspberrypi.org/magpi/rc-car-raspberry-pi/   Not enough instructions, but sounds good.

https://www.raspberrypi.org/blog/self-driving-car/          Wow. Something to aspire to.

Now I have updated the OS to Raspbian Stretch, and WebIOPi doens't work any more. There are workarounds on the net, but it is obvious that WebIOPi is not being supported or developed any more. One of the comments in the forum recommends Blynk http://www.blynk.cc/ and at the top of the WebIOPi page there is an later generation of the program called Cayenne.

I will test each of these and see if their features  are any good.  My base Raspbian will be Stretch.


Cayenne:   I will try it on SD card #1. It is available at https://mydevices.com/

Looked like it was working smoothly, but:
Fri 10 Nov 16:36:10 UTC 2017 Installing myDevices agent
0
Fri 10 Nov 16:39:20 UTC 2017 Found Python 3.5.3...
(50%)
Fri 10 Nov 16:39:20 UTC 2017 Copying agent libraries
(55%)
Fri 10 Nov 16:39:30 UTC 2017 Installing python utils
(60%)
Fri 10 Nov 16:40:41 UTC 2017 Installing software components
Fri 10 Nov 16:40:42 UTC 2017 Cannot install for Python 3.5.3 : missing development headers\n
Fri 10 Nov 16:40:42 UTC 2017 Finished agent code
Fri 10 Nov 16:40:42 UTC 2017 ERROR: myDevices cannot be installed - please check errors above

Oops, I forgot to do all the usual things with a new installation of Raspbian. Will do an update and upgrade and then try it again.

Error reports on Cayenne forums suggest that Wheezy is the only version of Raspbian supported.

Le't move on to Blynk

Blynk  Looks like the support for the Raspberry Pi is an afterthought, and also needs a Blynk Server. It is available at http://www.blynk.cc/
Needs special  software on the  Android/Apple  controller.  I will try it on SD card #2

The documentation looks like it steps you through the startup process very clearly, but soon comes to a dead stop. I have my Raspberry Pi [Stretch] fired up and prepared, the App installed on my Tablet [Android] and logged in, and I am following the instructions on my PC. The instructions are to download, unzip and install the libraries in my Arduino IDE, wherever that is.

Also I have to use an Authorisation token that Blynk have sent me, that is in my email inbox on my PC. I suspect that it is needed on my tablet, but am not sure.

Eventually I find a section in the docs on preparing the Raspberry Pi. I noticed it in the Table of Contents on the left hand side of the screen.  It seems straightforward and as I am ssh'd into the Raspberry Pi I can easily copy and paste the Authorisation code into the Pi.

No, This does not work either. The first instruction that I paste into the Raspberry Pi gives the following error message:
curl -sL "https://deb.nodesource.com/setup_6.x" | sudo -E bash -

## You appear to be running on ARMv6 hardware. Unfortunately this is not currently supported by the NodeSource Linux distributions. Please use the 'linux-armv6l' binary tarballs available directly from nodejs.org for Node.js v4 and later.


I'll try to resolve it, but if this first command causes this sort of problem, what will the others do.


Can't fix this. At Node.js, I tried to download the armv6 for ARM and the response was '404 - file not found' 


May have to follow these instructions: 

https://raspberrypi.stackexchange.com/questions/48303/install-nodejs-for-all-raspberry-pi

Note that the Raspberry Pi being used is a Model B Rev. 1.


From a suggestion on that web page I went to where a number of scripts to install node.js had been created and used https://github.com/sdesalas/node-pi-zero/blob/master/install-node-v6.11.3.sh


I connected to my Raspberry Pi using ssh, then opened a new file with nano, and copied the contents of this script into it, and saved it. I then changed its properties to rwx.rwx.rwx and executed it.  This failed because a number of directories did not exist according to the unlink command. But they do.  


I am starting to think that this is a lot of work that is not getting anywhere, and I do not know what to do now, so will give up on Blynk.


If anyone knows of another system that I can use to control my Raspberry Pi Model B rev 1 running Raspbian Stretch, I am willing to give it a try. 


[13/11/17] Ben suggests that I could put Alexa on my Raspberry Pi 3, but that reveals a problem. I'll have to convert my SD cards back to Jessie to support WebIOPi on my car, and to free up my MicroSD cards.   So SD card #1 will now be Jessie and WebIOPi, MicroSD card #3 will be stretch and available. 

[14/11/17] SD card #1 is now Jessie, running python 2.7.9 and all fitted up with WebIOPi, BUT it doesn't quite work.   I get the header, but not the buttons.  

Should it be Python 3? 

BRANCH: I have finally got the header pins soldered on to my Raspberry Pi Zero, and powered it on using  Micro SD card #3 which is:

cat /etc/os-release       -- Jessie

Python                        -- 2.7.9

It works completely

/BRANCH

Changed Html  and python script to the examples in the WebIOPi site. They didn't work 


How do I remove webIOPi? I'll start again, but I don't want to have to reimage.

[16/11/17]
Reinstalled webIOPi but it doesn't work because it gives an error GPIO not defined. 
I did a search and found: https://www.raspberrypi.org/forums/viewtopic.php?t=98981
see remark at Wed Jan 06 2016 by Brian. 

here is his page: http://www.blavery.com/BotSoftware-RPI/brian2012class.nfshost.com/where-are-we/index.html

Went to his pages and downloaded new copy and will try it. 

Used unzip Web* to unzip it, 
installed it, changed config file back to mine, and started it

Nope failed "GPIO is not defined." 

[17/11/17]
Start from fresh. Prepared SD card with Raspbian Jessie dated 2017-01-11
Added ssh file to both partitions! 
Added Interfaces and Wpa_supplicant files.
Added RC-car/html/index.html and rc-car/python/script.py
added webiopi-1.0.7-p zip file - saves moving it there later. The only other file I will have to put on is the webiopi config file. (I hope)

Now ssh into it, raspi-config to expand system to use whole memory, and update. This time I will not upgrade.

All done, and when I connect I get the header and the 404 favicon.ico not found. 

D.A.M.N.


Move on.
http://madsmaddad.blogspot.co.uk/2017/11/webiopi-is-obsolete-long-live.html