Welcome! Log In Create A New Profile

Advanced

PIC32 to ANDROID device

Posted by kev1953 
PIC32 to ANDROID device
September 28, 2014 12:54PM
The problem with any electronic project is how to make a professional looking user interface, you can have switches and a LED display, a LCD 2/4 line text display, even a touch panel with colour screen.
All these will work but all have the same problem, how to house them so the end product looks good. I have always been on the lookout for a ready made product that can interface with the electronics, now we have the Android devices, with prices now below 40 pounds for a tablet, this is now a affordable option.
This project will show how to connect a PIC32 board to a Android device using Bluetooth.
We need a app on the Android so that it works as a simple terminal, to do this there is a program called B4A (Basic for Android), then a simple program running on the PIC32 board
This example uses the PB1 board, and a Bluetooth board, using the TX and RX lines to talk to the Bluetooth over com 1 lines, com 2 stills talks to the PC and will act as user input and display for the PB1 (you need to Pair the Bluetooth devices)

PB1 program below enter bt_go() to start communications.

// cold \n\w200 tload \n\w300
// *****************************************************************************
// General purpose mini terminal
// Use mini_term(9600)    bt=00:13:03:08:91:43       ctr+j = 10 ctr+m = 13
// *****************************************************************************

function bt_go()
dim k$,k,k2$
dim x = 1
// setup com 1 port
    pps_out(?PRB4, ?U1TX$)
    pps_in(?U1RX, ?PRA2)
    print "pps set\n"
    io_pinMode(PORTB,4,OUT,WOFF)
    io_pinMode(PORTA,2,IN,WOFF)
    print "Comport ONE pins setup"
    comopen(1,9600,80)

// run termial loop

    print "Termial running\n\r"
    while x = 1                             // loop while x=1 forever
        if comkey?(2) <> 0 then
            k=comkey(2)                     // get key from keyboard
            if k = 27 then; x = 2; endif    // esc key press exit loop
            print chr$(k)                   // character
            k$=k$+chr$(k)
            if k = 13 then
                comouts(1,k$)               // o/p to serial port
                comout(1,10)                // o/p to serial port
                k$=""
                print "\n"
            endif
        endif

        if comkey?(1) <> 0 then
            k=comkey(1)                     // get key from host NB
            if k = 10 then; print "\n"; endif
            k$=chr$(k)                      // character
            if k <> 10 then;print k$;endif  // echo
        endif
    wend
endf


Sorry in advance if any of the steeps below are incorrect, trying to remember !
The documentation with B4A is very good see page below. If any doubt follow their instructions.
B4A (Basic for Android) can be downloaded for free here [www.basic4ppc.com]
And the B4A-Bridge that allow you to transfer the app produced by B4A to the device this is downloaded to your Android device
Also the Android JDK V7 (a big file) and the Android SDK file.
These take a little setting up but not too bad, and once it's done then it's simple from there.
Download the fee vision, and run the installer from the setup wizard, launce B4A
You need to set up the Paths for the files, select Tools, Configure Paths, and select the javac.exe and android.jar paths, leave other two empty
Setup Done..

The Android terminal program (app)....................
I have modified a version of their Serial example. This Serial library requires Android OS 2.0 or above (API level 5 or above).
You can download it from [cmoregames.com]
Un zip the file, and from B4a go to File, Open Source and from the folder you un zipped to open SerialK
Open Tools and select B4A Bridge and select Connect - Wireless, select New IP.
Run app B4A Bridge on the Android device, at the top it will show My IP: address, enter this into the box on the PC
Tap Start - Wireless on the Tablet, you should then see Status: Connected

Select Release from the drop down menu at the middle of the B4A screen, then Click on the right facing arrow to transfer the APP.
The compile window will open and show the progress.
A box opens on the device select install, if everything has worked correctly you will get a display of a text list box, a text box with a send button
and five buttons.
To connect to the Bluetooth tap the menu symbol bottom right, and Connect to Bluetooth device on the PB1
It should show Connected successfully

If you now type in the small text box then tap send this should be displayed on the PC screen on your terminal program.
Tap a button will display L U D R & OK, typing end with CR, will display the text on the Tablet.
This is just a basic setup to get things working, I hope to add more as time permits
Please give feed back if you found this helpful (or other wise)



Edited 1 time(s). Last edit at 09/28/2014 01:07PM by kev1953.
Re: PIC32 to ANDROID device
March 03, 2017 10:30AM
The Microchip PIC32 Accessory Development Start Kit for Android is used for evaluating and developing accessories for Google’s Android operating system for smartphones and tablets. The MPLAB C Compiler for PIC32 is a fully-featured ANSI compliant C compiler for Microchip's PIC32 family of 32-bit microcontrollers. This application is a neat and powerful compiler fully compatible with the Microchip's MPLAB IDE and with other popular third party IDEs. Microchip offers high performance floating point and DSP libraries for the PIC32 included with the MPLAB compiler.

custom essay writing service
Sorry, only registered users may post in this forum.

Click here to login