Monday, June 3, 2013

ATmega has got a new friend: BeagleBone!

What happens when two awesomesness meet together?

Well, we get 2x AWESOMENESS :)

So, I've got the BeagleBone to talk to my AVR ATmega328, and here is how, from the scratch up to running.


Here is a list of what I used:


  




BeagleBone board - (http://beagleboard.org/Products/BeagleBone)
STK500 Board - (http://www.atmel.com/tools/STK500.aspx)
Sparkfun's Logic Level converter - (https://www.sparkfun.com/products/8745)
A mix of jumper wires

-----------------------------
Although I have used the ATMEL's STK500 board, you can use any other programmer
-----------------------------

I am not an expert or any thing close to it, I am writing what I did and learned for the convenience of other people


Step 1: Installing Ubuntu 13.04 "Raring" on the BeagleBone

source 1: elinux  Wiki (http://elinux.org/BeagleBoardUbuntu)
source 2: GigaMegaBlog (http://www.gigamegablog.com/2012/09/03/ubuntu-on-the-beaglebone-enabling-analog-in-pwm-i2c-and-spi/)


1.1 - On a linux machine, follow the following tutorial http://elinux.org/BeagleBoardUbuntu#Raring_13.04_armhf

the last step would be:


sudo ./setup_sdcard.sh --mmc /dev/sdX --uboot bone

note the red X, this should be replaced with the correct letter according to what ID your PC assigns to the SD card

e,g,:

sudo ./setup_sdcard.sh --mmc /dev/sdg --uboot bone



After finishing, the SD card should be ready, take it out from the PC and plug it in the beaglebone.


Connect your beaglebone to your router using an Ethernet cable, this is needed for downloading software and for easy access

Connect your beaglebone to a power source (for now, use the mini-USB port and connect it to your PC)

wait until Ubuntu loads up, it takes about a couple of minutes

using Putty, we can access the beaglebone to issue commands, this needs an SSH-server enabled on the beagle.



try to connect by choosing the options as above:

Connection type: SSH
Host Name: arm

if it connect, that is awesome, and you can skip the following section.

if it fails, we'll need to connect through serial connection:


On a windows PC, Check your device manager

On a Ubuntu machine, check the contents of the devices directory

ls /dev


check before and after connecting your beaglebone, you will find that an extra serial port is available, open that port in a serial terminal at 115200 baud rate, and hit the tiny reset button on the beaglebone (next to the 4 user LEDs),

You will see the system booting up, wait until it is ready and then do the following:
source: https://help.ubuntu.com/12.04/serverguide/openssh-server.html


sudo apt-get install openssh-server


sudo /etc/init.d/ssh restart


The SSH server should be up and running now and you should be able to remote connect using putty with the settings mentioned above.

The default username and password are
ubuntu
temppwd

That is, if you have not changed the password, if so please do so as soon as possible since your beagle is now on the internet with an SSH door

sudo passwd





Step 2: The I2C interface
source: http://www.gigamegablog.com/2012/11/04/beaglebone-coding-101-i2c/

You have one usable I2C interface, that is i2c-3, on BeagleBone System Reference Manual PG. 59, it is refered to as I2C2_SCL and I2C2_SDA (Port 9:19, 9:20)


First, let us check the I2C interface:


sudo i2cdetect -r -y 3

The output should be something like:



Let us connect some wires now, but first we should shutdown Ubuntu and unplug the USB cable

sudo shutdown -h now


wait for 5~10 seconds till the system shutdown, then unplug the USB cable

connect the circuit as shown below (modified picture from sparkfun (https://www.sparkfun.com/products/8745)):

Also, while you are connecting, connect an LED to PB0 and another to PB1 on the ATmega



Download and unzip the example code from:
https://github.com/MuazSalah/BeagleBone_ATmega
https://github.com/MuazSalah/BeagleBone_ATmega/archive/master.zip

Remember to change the makefile according to your hardware

Compile and program your ATmega, it will be assigned as an I2C slave at address 0x0A


Power up your BeagleBone again, after about 20 seconds, you will be able to SSH to it, when so, issue the command


sudo i2cdetect -r -y 3




download and unzip the example code:



wget https://github.com/MuazSalah/BeagleBone_ATmega/archive/master.zip

sudo apt-get install unzip

unzip master.zip

cd BeagleBone_ATmega-master/BeagleBone


run the python code:


sudo python LEDs_Blink.py










Additional resources:

Enabling file sharing (NAS) on the BeagleBone
http://elinux.org/R-Pi_NAS

This a link for a tutorial on Raspberry PI, however, it is exactly similar to BeagleBone except that the service (or deamon) name is smbd and not samba, so you say

sudo /etc/init.d/smbd restart

and not

sudo /etc/init.d/samba restart

This is very useful to view your files on your linux/windows machine

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

Final Notes:

1- I2C read is not working
2- Although the address is configured as 0x0A on the ATmega, the BeagleBone reads it
as 0x05, a factor of 2 which seems to be constant at different slave addresses


Logic Analyzer data:

* Write operation:

* Read Operation:








EDIT:


Finally, I found a way to read through I2C using the function readList(startAddress,Length) from the same Adafruit library, if I need to ready 1 byte, I should get 2 bytes from the I2C, e.g.

readList(0,2)

This will read 2 bytes from I2C, the first byte will be the I2C receive address, and the second will be byte[0] on the txbuffer of the I2C slave



Time to RoboCar the BeagleBone



Saturday, April 20, 2013

HD44780 - Custom Character Generator - The Making

A while ago, I've made a simple program which I called HD44780 Custom Character Generator, I think that now is time to share the source code and go open!

HDD44780 CCG on GitHub

Playing with BeagleBone



I've recently got my hands on a BeagleBone with the excuse of being the main brain of my RoboCar.

Little by little, it was becoming obvious that I got my hands on an awesom-full-ness world of truly powerful embedded programming.

In short, I can say, imagine that you can put your laptop on your robot instead of an Arduino!!

That is what BeagleBone does, it really is a small tiny computer which runs linux operating system, it is quite similar to the popular RaspberryPi (which I failed miserably to get).

BTW, have a look at the following comparison between (arduino-uno-vs-beaglebone-vs-raspberry-pi) [Makezine]


In this post, I want to show you how awesome and easy it is to use BeagleBone with an example of an ADC (I followed a tutorial GigaMegaBlog)

I made the following connections on Port 9 (picture is from Beagle Bone System Reference Manual)




now, you need to access the command prompt on the beaglebone, this can be done in two ways as far as I know:

1: Using BeagleBone's USB to Ethernet converter:

By default, once you plug in the BeagleBone, you will access the memory card, in Windows, you need to write click on the driver on My Computer and choose "Eject" not Remove Device Safely

After couple of minutes, the ethernet interface will be activated on IP 192.168.7.2


2: The other way is to connect your BeagleBone to your home network simply by plugging a ethernet cable to BeagleBone on one side and to your router on the other side. Depending on your network configuration an IP address will be assigned to your BeagleBone.

Ok now, after we got the IP address let us see which ports are open:

port scan (up to 3100)  reveals that following ports are open:

------------------------------------------------------------------------
PORT     STATE SERVICE

22/tcp   open  ssh

25/tcp   open  smtp

80/tcp   open  http

110/tcp  open  pop3

119/tcp  open  nntp

143/tcp  open  imap

443/tcp  open  https

465/tcp  open  smtps

563/tcp  open  snews

587/tcp  open  submission

993/tcp  open  imaps

995/tcp  open  pop3s

3000/tcp open  ppp
------------------------------------------------------------------------


what we need is really only port 22, the SSH

you can use putty with the IP address, username: root, and no password



Now we are inside BeagleBone!!!

I am not going to re-state what is nicely explained in GigaMegaBlog, rather I'll give the short form:

Inputs and Outputs and Analog Inputs are really assigned to files rather than variables like in normal microcontrollers, so the file which contains Analong Input values is located in the following folder:

/sys/devices/platform/omap/tsc

type in:

cd /sys/devices/platform/omap/tsc

cat ain1

the above code will navigate to the said directory and then will output on the screen the contents of the file "ain1"

the contents of this folder is really the analog value (12 bit resolution, 0-4096) of Analog channel 0 (yes, the index of the file is offset by 1)




playing with the pot:



AWESOME!!!! :)

I can also do it from my Android:









Friday, March 8, 2013

RoboCar - An Album

It has been quite a while since I posted about my RoboCar, my autonomous dream

I decided to make this post as an album of all pictures I've got relating to my RoboCar

Currently, I am using the orange car (truck, better said) you see below. I've already designed and ordered PCBs which represents an awesome Control System with dedicated functionality cards. This will form my Autonomous Dream.