Saturday, July 26, 2014

Setting up the pcDuinoV2 -- Wireless and xWindows

I spent some more time working on the basic setup of the pcDuinoV2 that Pete from the Milwaukee Makerspace asked me to play with.

First of all, the board was booting up into xWindows on startup.  I thought I disabled that feature using the configuration program that is in the OS but apparantly not.  I managed to get xWindows to stop loading by creating a file named lightdm.override in the /etc/init folder.  The only line it had was one word: 'manual'.  

Now, the device boots to a text-based screen but the resolution looks like it is 1024x768.  In order to fix that, I had to run the configuration program from the command line by typing 
 and then setting the screen resolution back to 1152x864-75.  Rebooted.   The screen still came up in the lower resolution.  Maybe there is a permanent fix for this but I don't have time to research it.  It is pretty easy to set the screen resolution after bootup.

Next, I worked on the wireless network card.  There are some pretty good instructions about enabling a wireless NIC in Ubuntu at this website:

First, I created a file named wpa_supplicant.conf in the /etc folder.  It had these lines in it:
network={    ssid="MilwaukeeMaker"    psk="secretPassword"}

Next, I put these commands in /etc/network/interfaces

auto wlan3iface wlan3 inet dhcp    pre-up wpa_supplicant -B -Dwext -i wlan3 -c /etc/wpa_supplicant.conf    post-down killall -q wpa_supplicant

That's it.  The initial setup of the pcDuino is done.  
  • it boots to the command line
  • can connect to it at pcDuinoV2.local on any network because of Avahi
  • all upgrades are done (updates still don't seem to work)
  • wireless networking works
The next phase in this project is to build the robot base and control it with the
pcDuino.  In order to keep things moving, I ordered a Motor/Stepper/Servo Shield for Arduino v2 Kit from Adafruit.  

Since the pcDuino has Arduino compatible pins on it, shields made for the Arduino will work with the pcDuino.  I can use the motor shield to learn how to control motors with the pcDuino.  That should take a few weeks.  In the meantime, I will try to find parts for the base.  I'd like to find or make as many parts as possible at the Makerspace.  

Finally, I think I would like to make a robot that looks like Wall-E.  This means, I will need treads instead of wheels.  I did a bit of research into treads and they are not cheap.  Maybe I can 3D print something. 

Saturday, July 19, 2014

Fun With The pcDuino V2 -- First Looks

Pete from the Milwaukee Makerspace asked me to play around with a pcDuinoV2 that the 'space had sitting around.  I am tasked with making something awesome with it.  One idea I had was to make a  wifi enabled, remote controlled video surveillance robot.

At first, I was thinking that the robot could roam around the Makerspace, controlled by curious people on the internet.  On second thought, that would be a bit creepy.  Plus, the robot would get under people's feet or stuck on stuff.  Maybe the robot would be more accepted by the Makerspace members if it looked like a Dalek.  Think about it.  A five foot high Dalek driving around the Makerspace, controlled by someone on the internet.  That is not at all creepy.  Also, it would probably be pretty easy to add a speech synthesizer to the robot.  The person on the internet could type in some text and the synthesizer would speak it -- in a Dalek voice.  "Exterminate!  Exterminate!"  Awesome!

Another idea would be to combine the robot with the elevated train project that was discussed on the Makerspace's Google Group a year or so ago.  The original idea was to have an elevated train track that ran near the ceiling in every room of the Makerspace.  The track would be a big loop around the 'space.  In this case, instead of a train, the remote controlled robot would be on the track.  People could make it move around and point the camera at interesting things.  The robot would not get in anyone's way and possibly be less creepy.

Okay.  Enough daydreaming.  First things first: I need to make sure that the pcDuino works and get familiar with it.

The pcDuino has a USB port as a power input. That port is on the bottom of the board right next to the DVI port. I don't have a monitor with a DVI input. I have a DVI to HDMI converter that I can plug an HDMI cable in to.  The problem is that both a USB cable and the converter can not be plugged in at the same time. I was hoping that I could get both things plugged in at the same time if I applied a little pressure. Unfortunately, the extra force caused the USB port to separate from the board, i.e., I broke it off.  See the picture to the right. (Note to self: stupid decisions are made when tired.) 

The components on the pcDuino are surface mounted. I suppose it is possible to reattach the USB connector to the board but someone with better soldering skills than I would have to do it. 

Thankfully, the pcDuino has another USB port (labeled USB OTG) on the other end of the board.  It will also act as a power input port.  I used an external power supply that puts out 4.5V and 0.5A.  That is not enough to power the pcDuino when it runs xWindows.  Every time it started running xWindows, the screen would shutoff and I could not do anything.  I put the device away for a day or so.

Yesternight, I worked on the pcDuino some more at the Milwaukee Makerspace.  Again, I started out by using an external power supply for power through the USB OTG port.  The device would power up and start booting.  As soon as it started xwindows, the monitor shut off.  The power light was on and both RX and TX lights were on steady.

Next, I plugged the USB cable that supplied power into my PC's USB port and rebooted the device.  This time the screen stayed on in xwindows.  I guess my PC provides more Amps than the external power supplies I was using.  One problem solved.

Next, I plugged a USB keyboard into the USB A port and rebooted the device.  Pressing F8 during POST got me into the configuration menu.  Using the configuration menu, I changed the screen resolution to 1152x864-75.  Note: the default user is ubuntu with a password of ubuntu.

I tried running apt-get update to update the Linux operating system.  It ran for a few minutes then gave an error saying, "W: Conflicting distribution: pcduino Release (expected pcduino but got  )".  Not sure what is wrong.

Next, I ran apt-get upgrade.  It ran for about an hour and installed a bunch of upgrades.  Re-trying apt-get update yielded the same results as before.

I wanted an easier-to-use text editor, so I installed nano.

Also, I installed avahi.  (Full instructions are here.)  Then, I changed the host name to pcDuinoV2 in /etc/hosts and /etc/hostname.  Now, it is possible to use ssh to connect to the device at pcDuinoV2.local on any network.  There is not need to determine the IP address assigned to the device.

Finally, I tried to get the wireless network card working but I could not figure it out.  There is a website that has some information about this:  Obviously, there has to be a better way.

One last thing, the device still boots into xwindows.  I need to figure out how to turn that off.

Well, that was enough work for one night.  Next time, I'll get the wireless network card working.  I also need to find a powered USB hub so I can use a keyboard and mouse at the same time, if needed.

Sunday, July 13, 2014

HESA is Populating Data to MySQL Server

For the last week or so, I have been working on MySQL coding in python on my Home Environmental Sensor Array.  This weekend, I put the finishing touches on the python code in the SQL library.  I have standard functions to connect and disconnect from the server, create an INSERT statement, submit a query, and process the results.  This makes it relatively easy to add SQL functionality to a python program.

Next, I added code to the HESA python program so it writes status records to a MySQL database on my website every hour or so.  The current water sensor status is recorded (which is a bit strange since the status is either 0 or 1 -- there is either water in the basement or not).  Right now, the HESA basically stops running if water is detected.  In the future, it may keep running and keep recording various readings.  Then, this status may be more useful.  Also, it will record false positives and give me the opportunity to do some analysis.

The other thing that the HESA measures right now is the number of times that current was detected on the input pin, i.e., the pin was set HIGH.  The HESA looks for power on the input pin for about one second.  During that second, it takes 1,000 readings.  The pin must be set HIGH for 500 readings in a row for the HESA to determine that there is water in the basement.  There is a variable that keeps a running total of how many individual readings were HIGH in the past hour.  That number is written to the database.

Each individual measurement is written as a separate row in the database.  This way, I don't have to add a new column for every new thing I want to measure.  I could measure the temperature in every room in my house and record a new row for each room.  This is modeled after the SAP plant maintenance measuring point functionality.  Each device or room I want to take measurements for would have a record in a table.  Each thing I want to measure on each device or room would have a record in another table.  The measurements themselves that are recorded are related to one of the measuring points.  This should work out well.

Finally, I made a PHP web page to display the most recent results.  It reads the last 48 readings from the database and displays them in a table.  It's not really very impressive at this point (well, maybe it never would be).  In the future, I would like to add more sensors to the HESA to measure temperature, humidity, CO2, radon, etc.  Then, the readings might be a bit more interesting.

In other HESA news, I was getting a lot of false positives where it detected water when there was none.  I think that was because I was using an electrical cable from a lamp.  The ends of the cable were together but covered in insulation.  They should not have passed electricity between them but apparantly, they were.  Now, I separated the ends of the cable and attached them to opposite sides of a four inch PVC pipe.  I have not had any false positives since I made that change.

Friday, July 11, 2014

Replaced the USB Port on my Nexus 7

I have an Asus Nexus 7 that I bought a few years ago.  I really like it but after about a year, it started giving me problems charging.  The Nexus would sometimes recognize when a USB cable was plugged in but other times not.  It was a pretty frustrating problem.  I might go weeks with the Nexus not charging.  Then, it would charge just fine for another few weeks.

Someone I know who had the same problem ordered a replacement part from a company in China that fixed the problem.  I decided to try it too.  The part is labeled as "New USB Power Charger Charging Connector Port Flex Cable For ASUS GOOGLE NEXUS 7".  It costs only about $30 including shipping from Amazon.  It arrived in a few weeks even though I picked the cheapest shipment method.

The part has a USB port and the headphone jack.  It also comes with a spudger and three small screw drivers, although only one of the screwdrivers is needed.

Installing the part was surprisingly simply.  The first step is to remove the back of the Nexus using the plastic spudger.  Unfortunately, the tip of the spudger snapped off almost immediately.  I had to use a small screwdriver to pry off the back.  Fortunately, the Makerspace has lots of tools and had a small flathead screwdriver.

After getting the back off, the connector cable is basically exposed.  There is a plastic piece over part of it but taking out three screws is all it takes to remove the piece.  The cable itself is held in place with six very small screws.  I just had to remove them to take the old cable out.  There is a cable from the motherboard that slides in to the back of the USB.

There is a silver piece on the front of the headphone jack.  The new cable did not come with one, so I took the old one from the existing cable and super-glued it to the new cable.

Re-assembling was just as easy -- just screw everything back together and snap the back cover back on.

After shutting the cover, I fired up the Nexus and plugged in the charger.  It seems to be working.  Hopefully, it will charge more reliably.  I am skeptical that the new piece was any better or that the entire problem was the USB but we will see.

Monday, June 23, 2014

MySQL and Python

Over the weekend, I decided to write some python code to work with MySQL databases.  I already have experience working with MySQL and PHP and I have a small library of PHP functions to access MySQL.  The goal was to get the same functionality working in python.  Then, I can start storing data from the HESA in MySQL tables.

The first thing I had to do was install a python library.  I did this by typing
sudo apt-get install build-essential python-dev libmysqlclient-dev
at the command prompt.  This library is supposed to allow PIP to install the actual python package. 

Next, I had to install PIP, the app that lets you install python packages.  I did this by typing 

sudo apt-get install python-pip

Once PIP was installed, I used it to install the MySQL python library by typing
sudo pip install MySQL-python
The documentation for MySQL and python is not really that great.  I spent way too much time researching how to do all this.  Once I got this far however, I was able to talk to the MySQL server.

I found a simply python program to connect to a SQL server and display the version of the database.  I was able to use it to query both my local copy of MySQL and my version on the internet.

Next, I converted all of my PHP SQL code to python functions.  I have functions to connect and disconnect from a SQL server.  I also have functions to create insert statements, fix values in insert statement to guard against injection attacks, and execute a SQL statement and return the results.  I was able to successfully test all the functions with my test database.

Now that I have my SQL libraries, I will create a table in my test database to store readings from the HESA.  If only I had the HESA reading stuff...

Measuring Light with a Beaglebone Black

I spent Friday evening at the Milwaukee Makerspace experimenting with a photoresistor on my Beaglebone Black.  I am still trying to learn more about how the BBB works and am going through some learning tutorials on the Adafruit website.  They have one titled Measuring Light with a BeagleBone Black that I was using.

Before I could do anything, I had to enable ADC in the slots file.  The slots file is in the /sys/devices/bone.capemgr.9 folder.  I did not have the correct rights to modify the file.  This was fixed by typing 
sudo chmod 666 slots
to give all users rights to modify the file.

Next, I enabled ADC on the BBB by typing 
echo BB-ADC > slots
while in the folder where the slots file is stored.  I did not have to reboot the BBB.  The change took affect immediately.

I spent a couple of hours playing around with the circuit.  It is extremely simply since it only has a resistor and the photoresistor.  The circuit is a voltage divider.  Basically, the BBB puts a constant 1.8 volts into the circuit.  The resistor keeps some of the voltage from going to ground.  The pin that accepts the incoming voltage on the BBB measures different voltages depending on how much light is coming in to the photoresistor.  The more light that comes in, the more voltage goes to the BBB in pin and not to ground.

I'm not really sure why it works that way but it does.

So, my first experiment with analog readings on the BBB worked.  Next, I would like to figure out how to measure DC volts on the BBB.  That will be a bit tricky because the analog input pins will not take more than 1.8 volts.

Saturday, June 14, 2014

Blocking Clash of Clans

My kids play Clash of Clans (CoC) a lot and I'm a bit worried about the addictive affect it has on them.  I want to limit access to CoC on my home network so I started researching how it could be done.

I have a Netgear WNDR3700v4 router that sits between the home network and the internet.  I also use OpenDNS to filter DNS searches.

The simplest way to block CoC with my setup is to block the port that CoC uses -- 9339.  On the Netgear router, click on the Advanced tab.  Then, Security, Block Services.

save image

Click the Add button.  Then, fill out the fields as follows:

Service Type: User Defined
save imageProtocol: TCP
Starting Port: 9339
Ending Port: 9339
Service Type/User Defined: Clash of Clans
Filter Services For: All IP Addresses

I could have only filtered the IP Addresses of my kids devices but that may change and it would be easy for them to get around.

Some web sites say that you can block access to Amazon's AWS servers since Clash of Clans is hosted on AWS.  However, I tried blocking keywords,,  Nothing worked.  I could still play CoC.  I searched the internet for the correct URL to block but I can't find it.

My Netgear router has a log that supposedly tracks every website that the devices go to, but it does not record CoC activity.

Finally, the Netgear router is very limited with security.  You can setup a schedule for blocking ports or sites but you can only have one schedule.  Plus when you block stuff, the scheduling settings apply to all of the things you want to block.  I'd like to be able to block some ports Always, and some ports on the schedule.  You can't do that.

Most home routers are limited like this.  Even the dd-wrt software has limited features.  I guess I will have to buy a commercial router to do what I want.