Posts tagged ‘ubuntu’

Using MPLAB.X on Ubuntu 11.04 64bit with Dwengo board

I have been using Pinguino for quite some time to program my Dwengo board from within Linux, but as the source code grows larger, the Pinguino “sketches” aren’t always the most convenient code structure. In addition, and more important, I notices some weird unstable behavior where initializing a string variable with string A worked fine but initializing it with another string resulted in the code not being able to compile. As Microchip has released a cross-platform IDE called MPLAB X, I tried setting it up on my 64bit Ubuntu (v11.04 aka the Natty Narwhal) today. This article is a step-by-step tutorial on how to compile your code with MPLABX, load it on the Dwengo board and run or debug it using the Dwengo programmer.

  1. Go to the MPLABX download page, select “Linux x86 (32 bit)” as the platform (there is no 64 bit version) and check the boxes “MPLAB IDE X” and “MPLAB C18 Lite Compiler for PIC18 MCUs”. Then hit “Download now”. Do it fast, because a reeeeally annoying video (which you can’t stop) automatically starts playing upon loading the page!
  2. Two installer files will start downloading, make them executable:
    chmod +x ./mplabc18-v3.40-linux-full-installer.run
    chmod +x ./mplabx-ide-beta7.02-linux-32-bit-installer.bin
  3. You can try to run the graphical installers (just double-click the files), but on my 64bits Ubuntu this gave the elaborate “Segmentation fault” error message. The problem is documented here, and solved by running the installers in text mode. So first install the C18 compiler:sudo ./mplabx-ide-beta7.02-linux-32-bit-installer.bin --mode text

    and then install the IDE

    sudo ./mplabc18-v3.40-linux-full-installer.run

    edit: @markgross got the graphical installer working, as explained here

  4. Just one more hurdle to go! As the MPLABX is a 32bits version and uses Java, it expects to run on a 32 bit java virtual machine. However, the default Java you’ll install on Ubuntu via the package manager is a 64bits version. Follow the instructions on this site to run the IDE using a 32 bits Java version. Basically you install a 32 bits Java in some folder and create a shell script which points the JAVA_HOME and PATH environment variables to this Java.
At this point, you installed the environment succesfully and you should be able to start it without getting any errors. I start the script created in step 4 with sudo, because otherwise I do get some errors (and I’m not that into sorting out all kinds of file permissions) of files being read-only.

Now we will install the Dwengo library. Download it as a zip file from here, and extract it. You’ll get two folders, one with a .lib file in it and another one with the header files (.h extension). In a terminal, cd to the extracted folder and copy the .lib file to the lib folder of mplabc18 and the .h files to the /h/ folder (the exact destination folder can differ on your system depending on where you installed C18):
sudo cp ./lib/dwengo.lib /opt/microchip/mplabc18/v3.36/lib
sudo cp ./h/*.h /opt/microchip/mplabc18/v3.36/h/

Ok, we are set to go! Fire up the MPLABX IDE and let’s create a project… In the file menu, click “new project”. A dialog pops up. Select “Standalone Project” and click “Next”.

The Dwengo board ships with a PIC18F4550, so select this as the device:

The Dwengo programmer is compatible with PICkit2, a MicroChip programmer/debugger device. So select this as the tool and click next. The nice thing about using this device with the MPLAB software is that we will be able to actually debug our code! That is breakpoints, step-by-step and other goodness instead of tediously writing variables to the LCD.

Select C18 as the compiler toolchain:

Finally, name your project:

A project structure is created, shown on the left. We will start out by adding the Dwengo library by right clicking “Library Files” and selecting “Add existing file”. Select the .lib file we downloaded earlier.

Next we add the linker file, needed for successfully compiling your code. Right click on “Linker files” and select the file 18f4550_g.lkr which you’ll find in the folder /opt/microchip/mplabc18/v3.36/bin/LKR (or something similar, depending on where you installed C18).

And now, finally, we can add some actual code 🙂

I used the Dwengo “blinking Leds” example, which you can find here. Once the code is added, right click your project and click “clean”. This will remove any previously compiled code and asserts that you are not working with any old version of your code.

Now right click your project and click “build”. I got a lot of errors on the console window, but clicking “build” once more successfully compiles and links all code. Perhaps this is some error with the IDE (remember this is still a beta), so remember to hit “build” twice every time… You should get output similar to this if the building succeeds:

make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/root/MPLABXProjects/the_stalker.X'
make  -f nbproject/Makefile-default.mk dist/default/production/the_stalker.X.production.cof
make[2]: Entering directory `/root/MPLABXProjects/the_stalker.X'
make[2]: `dist/default/production/the_stalker.X.production.cof' is up to date.
make[2]: Leaving directory `/root/MPLABXProjects/the_stalker.X'
make[1]: Leaving directory `/root/MPLABXProjects/the_stalker.X'

BUILD SUCCESSFUL (total time: 162ms)
Loading /root/MPLABXProjects/the_stalker.X/dist/default/production/the_stalker.X.production.cof...
Loading completed

And now the moment you have all been waiting for... Make sure you connected the programmer with USB to your computer and that the programmer is plugged into the Dwengo board. Hit "Run project" in the "run" menu. You should get the output

Connecting to programmer...
Programming target...
Programming completed
Running target...

You can also double click a line in the code and run “Debug project” from the debug menu. Now you can step through the code to inspect variables and check the flow of your code.. nice!

I hope this guide helps anyone also trying out the new MPLAB X beta on Ubuntu. The installation is a bit difficult, but it looks like a really cool product. Especially the debugging is something that will save me countless frustrating hours 🙂

August 28, 2011 at 8:44 pm 4 comments

Bluetooth communication between BlueSMIRF and Ubuntu

A quick post on how to set up the Bluetooth communication between Ubuntu and a BlueSMIRF Modem.

My laptop was broken recently, and after getting a free new motherboard from the kind Sony people I reinstalled Ubuntu and tried to get all my software running again. Today I tried setting up the Bluetooth communication with my toy car’s BlueSMIRF (see previous posts) and  my laptop, and decided on documenting it. So here’s how to do it:

  1. (optional) It’s easiest if you can see what is happening on the BlueSMIRF side. Therefore, you’ll need a serial (TTL) to USB convertor like this one. Alternatively, if you have a Dwengo board (or similar), you can use that one by simly removing the PIC18F chip for a while:

    Now you can monitor the commands and data passing through the BlueSMIRF by opening “serial port terminal” (install it through the Ubuntu Software Center) on /dev/usbtty0 at the speed of your BlueSmirf (default 115200 baud)

    Details on the commands available are available in the Roving Networks Command datasheet.

  2. I didn’t get the default Ubuntu Bluetooth tool (the B in the taskbar) to play nice with the BlueSMIRF, so I installed “Bluetooth Manager” (BlueMan) through the Software Center.
  3. Power the BlueSMIRF, it should start blinking rapidly for about a minute. This means it is waiting for a connection. Once the rapid blinking stops, you can’t connect anymore!
  4. Click on the B in your taskbar of BlueMan, a window should open showing the Bluetooth devices in your environment. One of them should be FireFly (the BlueSMIRF). Right click on it an select “connect to SPP”:

    (the name in the screenshot is robot-719A instead of Firefly because I changed it earlier)
  5. Because this is the first time you connect to the BlueSMIRF, it needs to be paired. Therefore, Blueman will ask you the pass phrase. Enter “1234” (without quotes), this is the default passphrase of the BlueSMIRF.
  6. The bottom of the Blueman screen should now say “Serial port connected to /dev/rfcomm0”. Now you can open a serial connection to /dev/rfcomm0 using serial port manager (or from within a script) and start communicating 🙂
    The LED on the BlueSMIRF should turn green.

That’s it! Now the pairing is done, and you won’t need to enter the passphrase the next time you connect to the BlueSMIRF.

    December 19, 2010 at 11:15 am Leave a comment

    flash 10 on Ubuntu amd_64

    230  sudo apt-get remove flashplugin-nonfree flashplugin-installer
    233  tar xvf libflashplayer-10.0.32.18.linux-x86_64.so.tar.gz
    234  sudo mv libflashplayer.so /usr/lib/mozilla/plugins/
    Flashplayer 10 is not yet supported by Adobe for amd_64 Linux architectures, but they do have an alpha relase in their labs: http://labs.adobe.com/downloads/flashplayer10.html. Here’s how to install it (Thanks to these guys, only the download url has changed. ).
    sudo apt-get remove flashplugin-nonfree flashplugin-installer
    wget http://download.macromedia.com/pub/labs/flashplayer10/libflashplayer-10.0.32.18.linux-x86_64.so.tar.gz
    tar xvf libflashplayer-10.0.32.18.linux-x86_64.so.tar.gz 
    sudo mv libflashplayer.so /usr/lib/mozilla/plugins/

    October 2, 2009 at 4:59 pm Leave a comment

    Switched to Ubuntu!

    My laptop was getting on my nerves again, acting slow and dodgy (even though I formatted it only a few months ago). I was feeling adventurous and decided to kick my Windows out of the hard drive and install Linux on it! Asking my friend Bert what is the best Linux distribution in his opinion, I was pointed at Ubuntu. So Ubuntu it is 🙂

    6109ubuntu_logo

    Not a day after deciding to clean up the computer I am happily using my Ubuntu. And the cool part is I can just keep using my favourite applications:

    • Pidgin chat client is included in Ubuntu by default
    • Virtualbox has a linux version. This will also allow me to run Windows in case I get homesick 😉
    • Dropbox for sharing my files between work and home
    • Xmind for creating mind maps and notes
    • Google Chrome (although it is not already stable, f.i. the security features don’t work yet)
    • Evernote (using Wine, a Linux app that allows you to install and run Windows applications)

    I’m a bit afraid of my more exotic hardware (dvb-t stick, PIC development board, …) but haven’t tried it yet.. But very positive so far!

    edit: I got my DVB-T stick working without problems :-). It’s a Pinacle 72e stick, and it is natively supported by Ubuntu. I used Kaffeine player to first test it and it found all my channels without problems. Than I got things working in MythTV using this guide.

    September 10, 2009 at 9:17 pm Leave a comment


    Feeds

    Articles to be written…

    Twitter – kr3l

    my del.icio.us

    RSS Google Reader Shared Stuff

    • An error has occurred; the feed is probably down. Try again later.

    RSS Listening to..

    • An error has occurred; the feed is probably down. Try again later.