Monday, October 26, 2015

Paint Flow Control Project, Chapter 3.20, Getting Started With the Beaglebone and the 4D Systems LCD

With one of Heide's paintings in the background.
In the last post, I said I was proposing to Vivid Inc and UEI that I use the Beaglebone Black (BBB) and a 4D Systems 7" LCD touchscreen to do the paint flow control and also handle the Monitoring, Supervisory and GUI (MS&GUI) tasks. I had originally planned to use a Digi International BL2600 Single Board Computer to do the control and have it communicate by Ethernet to a PC which would do the MS&GUI part of the system. However, Thomas Nguyen suggested using a touchscreen LCD panel instead of a PC. Recognizing that it is a great idea to get rid of the PC, I then realized that the BBB had sufficient on-board hardware and was sufficiently fast to do the whole job of controlling the paint flow and the MS&GUI. Then I found the 4D Systems 7" touchscreen LCD panel that would accommodate the BBB.

So plunging ahead, I purchased a BBB from Amazon. It included a 5V power supply, a USB cable and a small plastic box. The unit soon arrived and I got going with the Getting Started info at (BBB Getting Started), first connecting the BBB to my PC thru the USB cable. The BBB came with an Angstrom Linux operating system in the onboard flash memory but the Getting Started instructions recommended updating the OS. But which OS to use: Debian, Ubuntu ...? After checking around, I read somewhere that the Debian distribution was easiest to use and decided to use it. I figured that I could switch to the Ubuntu or some other Linux distribution if the Debian didn't work out.

In order to upgrade the Linux OS, a 4GB or larger microSD card is needed and the Debian distribution is loaded onto the microSD, then the microSD is plugged into the BBB and the OS is "flashed" to the onboard flash memory. The Debian distribution can be downloaded from (Linux Downloads) to a PC and the image loaded into the microSC card per the instructions. I wasn't really sure I needed to upgrade the OS from the Angstom version to the Debian, so held off for a day or so but then decided to go ahead and replace the Angstrom OS with the Debian OS because I wanted to install Matplotlib and Numpy, and figured that I should get the latest versions from the Debian distribution, Again following the Getting Started instructions, I "flashed" the Debian into the onboard flash memory. Python etc come with the Linux distribution but require an installation operation to take it from the already flashed onboard memory to a working area in the flash memory. At least, I believe this is the way it works. I hadn't realized that Python was included in the distribution and the whole process seemed somewhat mysterious. I installed Python, Matplotlib and Numpy according to the instructions on the Matplotlib website (Installing Matplotlib) using the "sudo apt-get install Python" sort of instructions.

Fortunately all this went very smoothly and I then had an updated BBB with the Debian Linux distribution including Python, Numpy and Matplotlib.

My next step was to try to run my Python Fuzzy Logic simulation code that I described in previous posts. I had borrowed a couple of books from the local library, Getting Started by Matt Richardson and the BeagleBone For Dummies book by Rui Santos et al. These books had guided me in getting the BBB running over Ethernet and also would be helpful in getting my code running on the BBB from the Debian desktop.

I had expected there would be problems running my code on the BBB since it would be calling Matplotlib instructions to make the GUI and at this point I had no display attached to the BBB but I figured I'd give it a try to see what happened. And I hadn't thought of it before, but I wrote my Python code for Python 3.4 and I had imported Styles in my code. Then when I ran my code, it first gave me some errors related to Styles. Only then I discovered that the Debian Python was version 2.7, and Styles was not available for 2.7. And when I checked some more, I found that the Debian Python 3.4 did not include Matplotlib. So I was a bit concerned that I might have a lot of problems running my code in the Debian Python 2.7. Fortunately I didn't really need the Styles features and was able to simply comment out the Styles commands. Then happily my Python simulation program ran all the way thru until the Python interpreter output an error relating to the display since it found no display to write the GUI. That is, no real errors resulting from the Debian Python 2.7. At the time, I really didn't understand the display error message, but wasn't overly concerned since I had expected some sort of errors relating to the absence of the display.

I had been planning on buying a 4D Systems LCD display panel, but cautiously wanted to hold off on the purchase until I could verify that the BBB was operating correctly and since the BBB has a micro HDMI connector, I decided to try connecting the BBB to our Samsung 40" LCD TV set. However, I needed a cable for the micro HDMI to the Samsung's standard size HDMI connector and so made a couple of trips to Fry's Electronics in nearby Concord, Calif, two trips because the first trip I mistakenly bought a miniHDMI to HDMI cable not realizing that there are two types of tiny HDMI connectors!

Anyhow, when I finally got the correct microHDMI cable and connected the BBB up to our Samsung LCD TV, the OS gave some errors that looked troublesome but then displayed the happy Beagle in the lower right hand corner of the screen. I didn't see any way to run the Linux Terminal, and since I was tired from my two runs up to Fry's, I almost decided to pack it in for the night but then referred to the Dummies book, that said "hey Dummy, just resize the TV screen" and lo and behold the tiny icons showed up for the Accessories, File Manager etcetera. Then using commands from the Dummies book, I was able to execute the "sudo su" command and then the "Python MyCode.py" command and my GUI showed up on the TV screen, shown below, and I was able to get my code going and simulating the Fuzzy Logic control by clicking the Enable button on the GUI.

BBB Debian Desktop Showing the GUI from my Fuzzy Logic Simulation Code.

I was elated and relieved at the same time that the BBB could run my simulation code even though I had written it for Python 3.4 and the Debian distribution uses version 2.7. Actually I could get 3.4 from the distribution but Matplotlib wasn't available on the Debian 3 distribution, so I was stuck with 2.7.

Talking with Thomas about it, he said he would get Vivid to purchase the 4D Systems LCD panel or I could go ahead and get it, to be reimbursed by Vivid later. So straightaway (well, the next day) I ordered the LCD panel from Mouser, getting a little better price than from Amazon, and the panel was delivered by US Priority mail in just two days.

So then I set about connecting the 4D Systems LCD panel to the BBB, a thirty-second process as I was very careful to connect it properly. Using the 5V power supply, the BBB booted up and quickly showed the happy Beagle on the lower right hand corner of the screen and also the tiny icons showed on the lower left corner that allowed me to start my Python code. Again, and anticlimatically, my code started running right away, doing it's thing to simulate the Paint Flow Control. However, as you can see below, my GUI was too large for the screen and will have to be resized. Not a big deal and something that I will do later. Notice the blue lines. Those are simply marks on the plastic covering made by the QC folks at 4D Systems.

Fuzzy Logic Simulation Code Running on BBB with 4D Systems Touchscreen LCD.

So all looks well so far for using the BBB and 4D Systems 4DCAPE-70T LCD Touchscreen panel, at least as far as the GUI and computing the Fuzzy Logic Look-Up-Tables for the Paint Flow Control System. However, I will have to design an add-on board for the BBB, called a CAPE, that will convert the PWM output signals to a 4-20 mA current for the paint pump and also to convert the 4-20 mA current from the flowmeter to a 1.8 VDC signal to be digitized by the BBB's Analog-To-Digital Converter.

With the use of the BBB to do the whole control system including the MS&GUI, the development job will be significantly simpler for me to complete. I had been expecting to have to program the Digi BL2600 for the control tasks and a PC for the MS&GUI task, plus program the Ethernet communication between the PC and the BL2600. So the job will be simpler and I believe it will also be more robust and reliable.

However, a minor detail  ;-) that I hadn't yet mentioned in this post: I don't yet have an agreement to complete the job! Hopefully soon.

No comments:

Post a Comment