Tuesday, March 29, 2016

Raspberry Pi to Arduino Serial problems

After spending the entire weekend trying to communicate smoothly from my Tkinter program on my Raspberry Pi to the Arduino with the nanpy firmware loaded via serial, I almost gave up. Yet, I did not give up and at the end of the weekend I had a break through. After I did away with the nanpy firmware, thinking that was the issue, I wrote my own Arduino program. In doing this I ran into another problem in communication, adding to the first. The first problem I ran into was that the serial manager in the nanpy program was raising an error after the first command was issued. I couldn't understand why this was happening over and over again, so I removed the nanpy firmware and wrote a very simple serial communication program and loaded it on Arduino. In doing so, I ran into my second problem. Apparently, in python 2, the serial.write(variable) function automatically converts your string to bytes and sends them over serial. In python 3 this is not the case. You need to encode your string before placing it into the function. This ended up working: serial.write(bytes('1', 'UTF-8')). Once I correctly encoded the string, I returned to my first problem. Where the connection was failing after one operation. Now, I should mention what I was trying to accomplish. The Pi was telling the Arduino to turn a servo motor. Thinking back on this I feel pretty dumb. After noticing that the serial channel that the Arduino was connected was changing after every command I sent, I finally realized that powering the Arduino with the Pi was the obvious problem. Duh, ultimate learning moment. Powering a 5v Arduino from a 5v Pi and trying to turn a 6v motor was causing the Arduino to power down after every operation and power back up on a different serial channel. I had another power source set up and in place for use because I knew that I would need more power for my project but during testing purposes I had totally forgotten this. Maybe this will help people in the future who can't understand why their Arduino will not remain on the same channel.

Friday, March 25, 2016

Pi / Aurduino Master/Slave relationship

Today we install Raspberry Pi to Arduino software that lets you turn you add more functionality to your Raspberry Pi by adding all the functionality of the Arduino to your platform. We can do this by utilizing the Raspberry Pi as the master communicator and the Arduino as the slave handler. This would take along time for anyone to do accurately. Thankfully there is already a library that was developed and is kept up on github. It is known as Nanpy. Nanpy makes it easy to write code in python on your raspberry pi using the same library's already developed for the Arduino. It converts your code so that you can easily incorporate pre-writen library's for sensors and actuators on the Arduino so you don't have to write and c++ code.
It can be found at https://pypi.python.org/pypi/nanpy

All I did to install is follow the instructions on this page.
Only difference is that since I am programming my project in python3 rather than python2, I need to point my interpreter to the right install package.
Instead of using: sudo pip install nanpy
I had to use: sudo pip3 install nanpy
sudo is required because some packages in nanpy need root permissions of they will not install properly.

here is all the directions I followed:

sudo apt-get update && sudo apt-get upgrade

sudo apt-get install arduino

sudo apt-get install python3-serial

git clone http://github.com/nanpy/nanpy.git

git clone http://github.com/nanpy/nanpy-firmware.git

pip3 install nanpy

----

Connect your arduino to your pi via usb
open up the arduino ide
in the ide, select file, select open,
open your nanpy-firmware folder
open the Nanpy folder
and select the Nanpy.ino file
now select your port in the arduino ide that the arduino you are using is connected
and upload the sketch.

now from nannpy you import the Arduino library,
and any other library's you intend to use, such as: servo, eeprom, tone, ect.
easy as Pi....pun intended.



Tuesday, March 15, 2016

Project Closet v.1 part 2 (The GUI)

The next category of this project is the GUI. The idea, begging simple, is that since there are only 4 trays in the storage system, there should be 4 buttons in the form of pictures of the items in the box.
This will require a Pi camera to be added somewhere around the tray facing the entrance of the box, we will work on this in the future as well. As for the GUI, I have began with absolutely no knowledge of how to build this using python (or any other language). I search around and found a library known as Tkinter. Over the past two days I have been teaching myself how to use this library and I believe it is going quite well. Below is the code i have so far:
I may not have the most refined and efficient code at the moment, but what this creates is a good start. Here is a shot:
so overall, it is simple but a good start and close to what I need as a MVP (minimum viable product.)
Stay Tuned for more soon.

Project Closet v.1 Introduction (The Box)

I have chosen some weeks ago to start a mid term project for one of my CS classes. Since that time I have been unable to get my self away from it long enough to tell you all what I have been up to.
Now, I'm back. I watched an inspirational Ted Talk a few weeks ago, about how the future of computers, IoT devices, and technology in general should start to take a turn. How we, as creators, should think towards devices that we do less on and react more to our own gestures, habits, and needs. So, I decide to begin work on an Idea I have dubbed "Project Closet v.1". Project Closet v.1 is an interactive storage idea. The prototype itself may be rather modest but the idea has limitless bounds. The idea is that the storage system can react to you when you are around, or turn on, and show you a list (pictures) of items inside, and deliver one to you if you press the picture. Sounds simple but if it is implemented as a large pantry of food could do several things. It could present you with a meal idea based on what is inside, or alert when you are out of an item. Maybe it could even find the item on shopping sites such as amazon and order it for you if it learned you didn't like to be out. It could alert you when food is near expiration or you could check the items inside when you were on the go. It could keep an accurate list of what you have purchased over time and recommend better prices on common items. Maybe it is a simple night stand storage box, with a charger area for your phone, a place for your wallet and keys. It could alert you when you may forget an item in the mourning or wake you up presenting your medications or vitamins. Like I said, it is an idea limited only by the creator imagination.
I began work a few weeks back on a simple prototype using the Raspberry Pi B+ and the Arduino. I can break this idea down into a few categories, This is the first part:

The box*



 Here we will need the workings wired up. I have mounted a tray made out of wax cardboard with a cd for added support onto a plastic sprocket that has a plastic chain and is turned by a continuous rotation motor (about 6 volts). I used spacers to raise the table so it does not tangle knocking the chain off. Here is a picture the first setup with a small cable instead of chain=>.








Here is a more recent picture with the sprocket and chain added:
After I was happy with the table I then moved on to the PIR motion sensor. This sensor, located on the
front of the box will detected a person walking in front the box, relay a signal to the Raspberry Pi and thus will active the screen of the system. (I am not fully sure whether it will be operated by the Arduino yet since the Arduino has an analog to digital converter which could possibly rule out an false readings by averaging out where as the Pi can only read high or low digital values and may not get a full accurate reading. But we will see. Here are pictures of the PIR motion sensor mounted to the box:


Next I have added an LED seven segment  display in order to give an accurate display of the current tray that is at the opening. I also just kinda thought it was cool and had worked with one already.
Here are pictures of the Seven Segment Display:

After a few updates to the Tray, the mounting of the Arduino, and the external power port, below are the pictures where it currently stands.





Part 2 in new blog.