Real world interfacing

James Moxham

Member
Licensed User
Longtime User
I have got "Hello World' to work and now I'd like to use the software to do something in the real world, like turn on a light, or measure the temperature. I'd like to replicate something I wrote up a few years ago with a PC http://www.instructables.com/id/Control-real-world-devices-with-your-PC/ and replace the PC code with android basic.

But I'm a bit of a cheapskate, so I've got an apad (epad, "PandaPad"), and it does not have bluetooth. And it is only Android v1.6. It does have two usb ports via a little adaptor. The USB ports have 5V on them.

So I tried plugging in a USB to serial device which should give -9V on a few of the pins but no luck. It probably needs a driver.

So I'm wondering - what can a Pandapad do?

1) Are there drivers for USB to serial devices?
2) Is bluetooth possible on 1.6 - I see it needs a more recent version?

Maybe we can program it to output an audio file of a serial transmission? Build up a wav file of something slow eg 1200 baud using software then play it? A picaxe or arduino could translate that with a little analog circuitry to square up the waveform.

Or transmit data with a phototransistor looking at a particular part of the screen.

What about receive? Can you use the microphone - I see some recent comments that the microphone can't be used directly. But there is 'speech translation'.

And there is a camera. So it is almost easier to take a photo of an analog guage and process it than it is to read the value of a pot.

Am I missing something obvious here? Any suggestions would be most appreciated.
 
Last edited:

James Moxham

Member
Licensed User
Longtime User
Thanks++ for the quick response.

The microphone would be nifty.

As for drivers for USB to serial devices, is this a "hard" or "easy" problem to solve?

Or maybe a more general question, with respect to USB ports on these android devices, can the device act as a USB host, or is it always a USB slave? Could you plug in a USB keyboard for instance, eg USB Host mode on Motorola Droid

I also found this on a forum The devices you mention have to be plugged into the aPad when you boot it. You also need to put the USB port into host mode (see settings of the device, one option is USB HOST).

I will check that when I get home from work.

On the other hand - this thread has been going a long time. http://code.google.com/p/android/issues/detail?id=738
 
Last edited:
Upvote 0

James Moxham

Member
Licensed User
Longtime User
I can plug a USB memory stick into my Panda Pad and it is recognised but not any other devices. And solutions to using a USB serial device start talking about wiping the operating system which sounds like a way to make paperweights. So, lets look at <audio> as a way of interfacing with the real world.

First step - I read this tutorial http://www.b4x.com/forum/basic4andr...utorials/6484-connecting-your-device-ide.html and got the IDE to download using WiFi. Much much quicker than using a simulator!

Then, for the purposes of testing, I made a .wav file with 2 seconds of 1200hz square wave. This will change as we go along. I put the file on the sd card and compiled this program

B4X:
Sub Process_Globals
    Dim MediaPlayer1 As MediaPlayer
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Msgbox("Play a wav file", "First program")
   MediaPlayer1.Initialize( )
    MediaPlayer1.Load("/sdcard", "1200.wav")
   Msgbox("Hit the home key to exit", "Finish")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

And lo and behold, it works!

Now, I know from RF experiments that you need an initial tone to bias audio to a mid point as audio signals are AC coupled. On the picaxe the answer is to send a number (12) of ascii 'U' characters, which is 01010101. Also, the picaxe is limited to 14 bytes in a packet so that means packets can be short and simple. So that means a packet is going to be a fixed number of ascii U, then a fixed number of bytes. This means a packet has a known length. So it should be possible to create a dummy .wav file of that length, and hopefully then leave the header as it is and just change the data. The header format is pretty simple anyway https://ccrma.stanford.edu/courses/422/projects/WaveFormat/

So then it ought to be possible to create .wav files from Basic4Android from Ascii strings, save them to the sd card and play them.

That is the theory anyway. Back to coding.
 
Upvote 0

James Moxham

Member
Licensed User
Longtime User
Merci beaucoup ZJP

Today some Yagi antennas arrived from Canada, so I can start to experiment with longer range WiFi comms. Set up hotspots and beam a signal to those hotspots.

I know this will work because a friend did this 5 years ago as a temporary setup and we had a range of about 5km, but it was with Apple equipment costing thousands.

I'm amazed with Basic4Android.

In picaxe basic a line of code takes 1/1000 of a second. So I plugged this into Basic4Android and it finished instantly. So I increased the count. I'm getting just under a million lines a second! My head is reeling with possibilities now.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm amazed with Basic4Android.

In picaxe basic a line of code takes 1/1000 of a second. So I plugged this into Basic4Android and it finished instantly. So I increased the count. I'm getting just under a million lines a second! My head is reeling with possibilities now.
:) In most cases you will get the same performance in Basic4android as if you wrote the program in Java.
 
Upvote 0

James Moxham

Member
Licensed User
Longtime User
I found another USB device that works out of the box - a USB keyboard.

So - for real world input it would be a simple matter to hack a keyboard and use another micro to "type" characters. Maybe use a 4016 or reed relay.

I think I can get output working by creating a .wav file and reading it back with the player. I'll test that out next.
 
Upvote 0
Top