Thursday, 9 July 2020

Memory Cards, Applications and RC-Cars

This is doing my head in, so I have to get it down. I almost need a multidimensional spreadsheet.
My memory cards are numbered. The RC-car apps that I have developed are numbered, and the Cars themselves are numbered.

I did do some tests to see which cars would work with a PWM speed control, but I can't find the record of that experiment.

So CArd 4 is now in RC-Car 3
And Card 7 is in RC-car 2. Card 10 is a duplicate of card 7

Card 4:
App-py-7        PWM control of motor
                        Steering is  2 pin on/off control

App-Py-8       steering is PWM-servo
                       Motors driven by 2-pin on/off control

App-Py-PWM-Test          Motor control calculating PWM duty cycle
                       no steering

App-py.old   -> backup of py-7

CArd 7:
App-py  2-pin on/off control for both motors      Dated 2018-10-31 - An early one.
              using GPIO 18/23  and 10/11

Card 3:
App-py  2-pin on/off control for both motors      Dated 2018-10-31 - An early one.
              using GPIO 18/23  and 10/11
              with double push on forward to stop. (31-1-2019)




Friday, 12 June 2020

Raspios and Duplicating Raspberry Pi system

This one is in three parts. The Third part is resorting back to Raspbian Buster to try and get this working.

----------------------------

Ok, so I have not had any luck trying to do a diskcopy from one SD card to another, so I decided to just rebuild the system.

-----------------------------         PART 2
I Installed the latest Raspbian OS, now called Raspbios, onto uSD card #10, also a 16GB card and reinstalled all the software. For whatever reason the Wifi didn't work, so I am starting again.

1. Flashed Raspbios (May'20 version) onto card and set it up to enable ssh, and also downloaded the python/HTML files into it.

2. Boot on Ethernet in R-PI card B-rev2, and update and install the driver for the ZD1211 card, and then configure the network.  [ initial IP = 26]
sudo apt-get update
sudo apt-get install firmware-zd1211
Use raspi-config to set Ethernet to 192.168.1.9/24 and wireless to 192.168.1.8/24
- this doesn't work- it cannot find wireless (dongle was not plugged in) and I don't find where to configure Ethernet.

So: edit dhcpcd.conf and wpa_supplicant.conf to configure network and wireless using the usual settings

Note that I discovered that wpa_supplicant was set to the ISSID of the downstairs router, not the local one.

Having done this, reboot and see what IP address the Ethernet picks up. Typically use fing for this.
Result - both Ethernet (9) and Wireless(8) work.


3. Install Flask and configure and get it running on wireless.
sudo apt install python3-flask

Put the shell script in Home directory and also in RC.local

File go-car.sh contains:
      export FLASK_APP=/home/pi/rc-car/app.py
      flask run --host=192.168.1.8

Tried to run it: "No module called gpiozero" error.
Found gpiozero site https://pypi.org/project/gpiozero/
It says "pip install gpiozero"
But pip command not found. 
Installation instructions:
sudo apt install python3-gpiozero
try again:
Interesting error: 
* Serving Flask app "/home/pi/rc-car/app.py"
* Environment: production
  WARNING: Do not use the development server in a production environment.
  Use a production WSGI server instead.
*** basically I can ignore it.

4. Install Access point software.
At this point follow my previous post:
https://madsmaddad.blogspot.com/2020/02/raspberry-pi-ad-hoc-wireless.html

Found that the link within it to Raspberry Pi documentation on setting up an Access Point had disappeared.
 Used  this and edited dnsmasq.conf as suggested
https://www.raspberrypi.org/documentation/configuration/wireless/access-point-routed.md
Skipped the bit about Internet Routing.

Created /etc/hostapd/hostapd.conf containing
country_code=GB
interface=wlan0
ssid=rc-car
hw_mode=g             ??? Should be b? --> g is valid for zd1211
channel=7
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Ashmeads
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

rebooted.

No wireless Lan found.
Think I'll have to edit to make hw_mode B

Changed hw_mode to b
changed channel to 4
comment out wpa_pairwise and rsn_pairwise because they were not used in normal operation.

Reboot with WiFi   -- no joy.

Check IP addresses, though this is not the problem.

Replaced Hostapd.conf with this from old version:
interface=wlan0
driver=nl80211
ssid=rc-car
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Ashmeads
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Still didn't work. The difference that I noted that made me do this is the Driver line. 

-- -- Have stuck the question up on the Raspberry Pi Forums as  # 277183

Now edited to be:

country_code=GB            # added
interface=wlan0
driver=nl80211
ssid=rc-car
hw_mode=b                  # changed from g to b
channel=4                  # changed from 7 to 4
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Ashmeads
wpa_key_mgmt=WPA-PSK
# wpa_pairwise=TKIP        #commented 
# rsn_pairwise=CCMP        #commented


No luck, and it looks like the Pi has crashed? No activity light action. Plugged in Ethernet, Life.

dmesg output: 

[   20.148077] usb 1-1.2: reset high-speed USB device number 4 using dwc_otg
[   20.608179] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
[   20.609695] zd1211rw 1-1.2:1.0: phy0
[   20.613235] usbcore: registered new interface driver zd1211rw
[   24.315134] random: crng init done
[   24.315160] random: 7 urandom warning(s) missed due to ratelimiting
[   25.769531] 8021q: 802.1Q VLAN Support v1.8
[   26.877003] Adding 102396k swap on /var/swap.  Priority:-2 extents:1 across:102396k SSFS
[   26.922096] smsc95xx 1-1.1:1.0 eth0: hardware isn't capable of remote wakeup
[   26.923339] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[   27.007719] zd1211rw 1-1.2:1.0: firmware version 4725
[   27.051722] zd1211rw 1-1.2:1.0: zd1211b chip 0586:3410 v4810 high 00-19-cb AL2230_RF pa0 g--NS
[   27.105805] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
[  261.167345] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[  261.180014] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
[  263.237497] ICMPv6: process `dhcpcd' is using deprecated sysctl (syscall) net.ipv6.neigh.eth0.r
etrans_time - use net.ipv6.neigh.eth0.retrans_time_ms instead



pi@raspberrypi:~ $ iwconfig
eth0      no wireless extensions.

lo        no wireless extensions.

wlan0     IEEE 802.11  ESSID:off/any
         Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm
         Retry short limit:7   RTS thr:off   Fragment thr:off
         Power Management:off


Release notes for Raspberry Pi OS don't have anything useful. 

Tried Raspi-config to set Localisation settings (option 4) But it came back with could not communicate with wpa_supplicant



---------------------------        PART 3
Giving up on Raspberry Pi OS and going back to Raspbian Buster. If I get that working I might try a dist-upgrade on it.  So repeating the instructions as above. 

Flashing buster 2020-02-13 (looks like full system) into 16GB uSD card #10
setup ssh
edited dhcpcd.conf and wpa_supplicant.conf
added rc-car stuff

It should boot to ...9  and have updated ZD1211, and normal update on new installation procedure.
Install Flask and rc.local bit. 
This time I tried to get ahead so I tried 'pip install gpiozero' and the system responded that gpiozero is already the latest version.  OK. 

At this point reboot with wireless and check.   OK It works. 
I am connected via wireless (IP ...8) and I guess now have to install the AP stuff.

Followed instructions, and rebooted.   Wifi network not there, cannot connect.
----------------------------
Came across this:
https://github.com/raspberrypi/linux/issues/3671

It's not just my problem.

Interesting suggestions:
https://hawksites.newpaltz.edu/myerse/2018/06/08/hostapd-on-raspberry-pi
 -- This is an excellent article, even if dated 2018.


This one is out of date: ubuntu 14.04 refers
https://seravo.fi/2014/create-wireless-access-point-hostapd

Hostapd documentation, current april 2020
https://wiki.gentoo.org/wiki/Hostapd

another interesting link:
https://thepi.io/how-to-use-your-raspberry-pi-as-a-wireless-access-point/

--------------------
from this https://unix.stackexchange.com/questions/119209/hostapd-will-not-start-via-service-but-will-start-directly   I set /etc/default/hostapd line  to spell out the full file name of the hotapd config file
DAEMON_CONF="/etc/hostapd/hostapd.conf"

This is because of lines in syslog about config file not found
"Jun 18 19:44:00 raspberrypi systemd[1]: Stopped Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator.
Jun 18 19:44:00 raspberrypi systemd[1]: Starting Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator...
Jun 18 19:44:00 raspberrypi hostapd[15736]: Configuration file:
Jun 18 19:44:00 raspberrypi hostapd[15736]: Could not open configuration file '' for reading.
Jun 18 19:44:00 raspberrypi hostapd[15736]: Failed to set up interface with
Jun 18 19:44:00 raspberrypi hostapd[15736]: Failed to initialize interface
Jun 18 19:44:00 raspberrypi systemd[1]: hostapd.service: Control process exited, code=exited status=1
Jun 18 19:44:00 raspberrypi systemd[1]: Failed to start Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator.
Jun 18 19:44:00 raspberrypi systemd[1]: hostapd.service: Unit entered failed state.             
Jun 18 19:44:00 raspberrypi systemd[1]: hostapd.service: Failed with result 'exit-code'.

Brilliant, It is There!














Tuesday, 2 June 2020

Thoughts on Business and Management (before 2011)

obviously written before retirement as I wasn't attending meetings any more.
--------------------------
I really shouldn't be allowed time to think.


On my way to the meeting today I was questioning in my mind whether we were a Business School or a Management School, forgetting of course that we are the Management group in The Business School.


I contemplated what each was: What is Business?/What is management?, and  came to the conclusion that in order to do management you needed something to manage, - a Business.


Then what does a Business do? It supplies something, whether it be a product, a service, a process, or a skill. (and other things?)


It needs to:
- Create  the product or service
- Market it
- Supply it to customers
- do it legally. And legislation is always changing.

Each type of these requires management, and the forms(?) of management may vary.  The functions of management that are required, based on the specialities available in the Business School, and thoughts that came out of the meeting today, are:

Bean counters (  Accounting and Finance) {- already a group}
Legal people   (Law) {-already a group}

- Strategy


- HRM


- Direction of the business (day-to-day management/decision making)


- Production management ( Not taught in the Business School)


- Project Management


- Data Management?


- Marketing


- Disaster Management ( Hopefully pre-emptive)


- ??

And all of these require, in different forms and amounts BI (business Intelligence) which comes out of or is parallel to KM (Knowledge Management), which comes out of Information Systems.  ( Is this where data management is?)


Therefore, as Dean Brady said, IS should be embedded in every aspect of the teaching in the Business School.


At one point my differentiator between the BS and DEC was that in DEC they were taught the in-depth stuff of Networking and Communications (and Software) so that they could design the next generations of the stuff, whereas in the Business School students were taught how to use it and put it together in order to optimize its use in the Business World, and overcome 'the productivity paradox' (Goldman 2003). Nowadays I think that this has changed. The networks are there in the Business and techies exist to look after them. We must concentrate more on the 'Information' in IS, and the optimization of that.


Sunday, 31 May 2020

Raspberry Pi as Casting device

31 May 2020:     We have a chromecast on the upstairs TV, but nothing on the downstairs TV so I wondered if I could use and Idle R-Pi for one. My R-Pi is a Model B rev 2, so it is quite old, and some of the Wifi dongles do not support use as a AP.

Here's links:

https://www.youtube.com/watch?v=OhNc2cSULWQ
directs to https://www.novaspirit.com/2017/09/22/how-to-use-raspberry-pi-as-chromecast/
needs raspicast on Android Tablet

https://thepi.io/how-to-use-your-raspberry-pi-as-a-chromecast-alternative/
The same.    used this one to make it.

https://www.instructables.com/id/Raspberry-Pi-As-Chromecast-Alternative-Raspicast/
The same.

https://www.makeuseof.com/tag/raspberry-pi-chromecast/
The saem, includes compilation and comment about using Kodi too.

None of these mention wireless configuration.
Loaded latest Raspberry OS on 8 GB SD card.
Installed usual network config stuff.
Wireless IP of 29

Have put question on the Raspberry Pi Forum.
 https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=197143

3 june 2020 I turns out that omxplayer that was part of previous Raspbian distros was not part of Buster, so i have installed it.

Hah – Got it working. Uninstalled Raspicast from my tablet, rebooted, Installed again and realised that the tab for files showed files on the R-Pi, then started youtube and shared to Raspicast second alternative after ‘queue’, to actually play. And it worked.

Not as good as Chromecast, but it played Youtube videos.







Wednesday, 13 May 2020

2020-May- Further experiments with Raspberry PI RC car - Can I make it respond faster

The starting point for this is using the R-Pi as an ad-hoc  connection so that I don't need an access point, as described here:
https://madsmaddad.blogspot.com/2020/02/raspberry-pi-ad-hoc-wireless.html

In a recent issue of Linux Format magazine I found an article about alternate ways of doing all this so I have to try them.

3 things that you can do:
1. Overclock the pi, done with SD card 4 in a R-Pi B and seems to work
2. Modify the amount of RAM that is used, but the Pi-B only has 256 MB so difficult to do and wonder if there is any measurable  advantage.
3. Use different Web interfacing. Article not much use, look further.

As SD disk 7 is the one active in Car3, I'll try overclocking it.
Just set overclocking to 950Mhz (high) from basic 700MHz.

June 8 2020
Just did a search on Speed optimization in Flask. Got some good results

https://stackoverflow.com/questions/39788630/speed-optimisation-in-flask

https://blog.socratic.org/the-one-weird-trick-that-cut-our-flask-page-load-time-by-70-87145335f679

https://damyanon.net/post/flask-series-optimizations/   Don't know how useful this one will be.

https://anthonyblackshaw.me/2018-02-17/speeding-up-url-for-for-flask


I have to think about how I will test these.  One thought is to build a new SD card  for the car 3 and use it as a test bed, or else to use car 2 which I have here and it has the servo steering modification. Thisn one uses SD card 4.  I think car 3 because the reactions will be more obvious.

First step will be to build a new SD card of the software, not forgetting the overclocking modification above.

I have used SD card 10 to duplicate 7. As an aside, I now have a backup of card 7 on my computer.
https://beebom.com/how-clone-raspberry-pi-sd-card-windows-linux-macos/    worked. - No it didn't. the file created was too large to blow onto the repalcement SD card.


I liked this tutorial.
https://towardsdatascience.com/python-webserver-with-flask-and-raspberry-pi-398423cc6f5d

14/6/20 Rebuilding System on another SD card. Connecting from Chrome on PC Via access point wireless, the response is very fast. So perhaps this is where I have to look for speeding up the system. When I have added the AP software to the R-Pi I'll connect the PC to it.

18/6/20 I think that word should be Ethernet, not wireless, But I will build a basic system (No AP)  and try that via Router wireless.

Wireless to Tablet is the slow item, so is it the browser/software in the tablet. How to test that.

20/6/20 The RC-Car on uSD card 4 responds pretty quickly to the tablet.
Must check again card 7 and 10 for response times.

Ethernet to PC - very fast
Ethernet to tablet, nearly as fast  - So that sort of says the Application on the Pi and the Wifi and Browser on the tablet are not holding it back.
Had a thought that it could be the AP software so searched for Hostapd causing slow action, and found hints that I should configure hostapd for wmm=1.

Now to test.
Humph. Wifi AP doesn't work at all. Not on house network or it's own.
from Dmesg:
  18.436844] usb 1-1.2: Direct firmware load for zd1211/zd1211b_ub failed with error -2
[   18.436875] usb 1-1.2: Could not load firmware file zd1211/zd1211b_ub. Error number -2
[   18.436888] zd1211rw 1-1.2:1.0: couldn't load firmware. Error number -2   


Difficult to resolve. Had to remove Hostapd, and update and then Upgrade SD card #7.  One of the things that seems to have happened is that the zd1211 drivers seemed to have disappeared so I had to reload them. That is probably the error above. Have got it working again with external AP, now need to reinstall hostapd and start again. 

                    











Thursday, 30 April 2020

CTC DIY Printer Z-axis wobble repairs

First, an example of the wobble: https://drive.google.com/open?id=1sz34dHOgt0r1nmJpUiQsRUgLw2h_Svmb

Now a solution suggested on Thingiverse, found from a youtube video:
https://www.thingiverse.com/thing:2135784   I printed this, and it was necessary to file out the groove on it due to the effect of the Z-axis wobble. The side of the piece shows the effect of the wobble ( see picture)



This is the mechanism that has to be modified: [Picture 2]



and this shows where the piece fits, [picture 3]



with the metal piece screwed into the white piece and the rest of the mechanism resting on it.

How to do it.
1.  Undo threaded bar from coupling and remove it.
2.  Remove slider rod.
3.  Undo metal threaded part.
4.  find appropriate screws and mount  this threaded part on to white piece.
5.  Replace slider rod, and clip white piece in to it.
6  Replace threaded rod, through mechanism and through added piece.
7.  Align x-axis mechanism  for correct vertical positioning.
8  Test
9.  If successful, repeat  1-8 on other side.

This works, much less wobble. Here is the final picture. As the rod wobbles so does the white piece, but the frame doesn't. I had to do both sides. One of the main difficulties was finding small screws that would go through the metal, screw into the plastic, but not protrudre into the dome of the white plastic where it would affect the sliding motion.  It was necessary to reset the nozzle height afterwards.


All of this thanks to jpnurro the designer who put it on thingiverse.


I am quite pleased with the results, but will still work on how I can stop the threaded rod from wobbling, which is the cause of the problem.

11 May 2020
The problem seems to have got worse again, I don't know why, except that the Z-axis spindle does seem to wobble around a lot.  I have tried putting shims into the coupler where I think I can centre the spindle, but that doesn't seem to help.

This morning I put the X-axis machinery up on trestles and have removed the Zaxis threaded spindle.  The Coupler wobbles. THIS IS BAD NEWS.

In effect, back to square one. Does this mean that the axle of the stepper is bent? I have  seen that mentioned in a YouTube video.  Or is it that the stepper motor is mis-aligned? One of the screws bolting it on to the frame was looser than the others.  No. The way that the axle turns indicates that this last is not the problem.

12 May 20202 Have replaced coupler with plastic tubing and wobble is so much reduced. No signs of wobble in the stepper motor  axle.





Monday, 20 April 2020

CTC DIY Printer improvements

This blog to document what I have done with the printer to try and improve it.

The current state is that I have been printing face masks and they are not very good because the sides are rippled.

I tried to adjust the baseplate height but on one side the adjustment screws were completely tight and on the other side almost completely undone. At this point I measured the height of the horizontal guide bar (X-axis) and discovered that it was 6mm higher at one end than at the other, so I adusted that by turning one z-axis screw until both sides were the same height from the base. I then adjusted the z-axis  position of the nozzle so that it was with the plate about half-way done up on the adjustment screws. A business card  worked well to get the nozzle-baseplate seperation correct.

One of the problems that I have not been able to resolve is that the threaded z-axis rods are not straight but have a bow in them. Each level of deposition of the print is 1/8th of a turn of this screw.  I have removed and tried to straighten this rod, but have not been successful. The results are obvious in the picture below as you can see on the white knight . The black knight  was the very first thing printed on the printer.



What can be noticed is that the ripple up the sides of the white knight is very close to the pitch of the thread of the rod. One implication could be that as the rod turns  it moves the nozzle head from it's perfect position and  gives a bit of an offset to each layer.

In the next picture you will see that at the top of the threaded rod where is is held by the top board I have added a bushing to hold the top of the z-rod more firmly. This means that the bowing of the rod will push against the other vertical guide rod and force the print head mechanism out of position.   If I remove this bushing that I have added, then the bowed rod would have room for play in the top mounting, and hopefully will not affect the print.








Picture one - Closeup of Knights.

Picture 2 = Left hand frame showing guide rod and threaded z-rod (bowed) with blue bushing.

Removing the bushing sort of goes against good engineering practice, but if it allows the z-rod to flop around and not affect the print nozzle, it may have to be that way. There is also a bushing on the rod on the right side of the machine, but we will see if this sorts the problem to some degree.