PDA

View Full Version : Android Basic Alternative



Charlie
- 16th February 2013, 10:20
If you code with Visual Basic, B4A is a good choice. However it's a bit too "object oriented" for my taste, so I'm looking for alternatives. I prefer good old procedural structures, like those used in PICBasic Pro, or Liberty Basic for the PC. I've been poking at RFO Basic which has the right language structure and the right price tag (it's open source, so free). It's available here: RFO Basic (http://laughton.com/basic/) You actually can code on the target device, or you can create a file on your PC and move it over, and you can of course create APKs for distribution on Google Play. There are some tools available, but it's relatively new and a bit thin yet. There seems to be a very involved user community as well.

Has anybody else looked at this one?
How about other alternatives more akin to PBP than VB?

mackrackit
- 19th February 2013, 08:53
Have you been able to write anything useful with it?

Charlie
- 19th February 2013, 10:33
Sure - I've produced a display program for a PIC project that is basically collecting sensor data and sending it by BlueTooth. The Android app reads and displays the data, and saves me carrying a laptop for a task a phone can happily do. I have not hit any real limitations with the language other than my imagination. I did uncover a bug and got a load with a fix within a few hours, which is way better than I'd see with a proprietary product.

All the major constructs are there, and all the smart phone platform advantages are accessible like BlueTooth, WIFI, position/motion sensors, GPS, file reads and writes, etc. as well as graphics tools and text dislay tools, and there are tools to produce standalone apps for distribution in Google Play. I guess my only concern is the double edged sword of open source and GPL - you get lots of code to reuse, but you must publish your source so you might lose any competitive advantage. Perfect for a hobbyist, and still usable commercially with caution.

Not a lot of posts, though, so I'm guessing not a lot of PBP folks are using it - or maybe not even doing Android.

Normnet
- 19th February 2013, 13:13
Does RFO basic include the advanced feature of "Ad Hoc WiFi" or point to point WiFi?

Norm

Charlie
- 19th February 2013, 13:54
Hi Norm. I'm not sure - I have not played with WIFI yet. In general RFOB uses the android/java/linux existing infrastructure to set up physical or transport layer stuff, then uses sockets or defined buffer accesses to move data in and out of those layers. So if your version of Android supports PTP WIFI (I don't think my old 2.3.3 does) you should be able to use it. RFOB really wraps the existing Java and hides the complexity to get you going fast without a huge learning curve.

But I'm pretty much a newbie too... I'm just looking for something that doesn't require me to write a dozen pages of objects to type "hello World" on the screen. B4A is nice for a big collaborative projects, but I don't generally do any of those. RFOB might just serve all of my needs. The manual is quite good. I'm not sure about other language alternatives if they even exist, hence my original post.

mackrackit
- 19th February 2013, 15:16
Not a lot of posts, though, so I'm guessing not a lot of PBP folks are using it - or maybe not even doing Android.
From what I have seen I do not think that there are that many here working with Android.

I am going to try RFOB when I get time. Not sure when that will be though.

rsocor01
- 19th February 2013, 16:18
From what I have seen I do not think that there are that many here working with Android.

Well, I have been using Basic4Android for a while. Unlike Charlie, I do like the fact that the program is object oriented. I think that it been object oriented it makes my life much easier.

Robert

spcw1234
- 21st February 2013, 19:58
I also am using B4A, though only a few simple apps so far. Learning how to make your app work with different screen sizes has been my biggest hurdle. Still having trouble with that :) I will check out RFO basic. Thanks for the link.

Tobias
- 4th March 2013, 06:22
I have been working with B4A for a couple of months and like it. Now trying to get PIC connected to a BT module to talk in Prefix mode. If any of you guys have experience I would appreciate some input.

I define all variables as BYTES. B4A crashes when it receives the data.

Send_BT:
Prefix1=0
Prefix2=0
Prefix3=0
Prefix4=4
RPM1T=34
RPM2T=65
RPM3T=232
RPM4T=45
debug Prefix1,Prefix2,Prefix3,Prefix4,RPM1T,RPM2T,RPM3T, RPM4T
Return

spcw1234
- 15th March 2013, 14:47
Did you ever get this working with prefix mode? I am struggling with the exact same thing. I can view the data with prefix disabled, but it crashes (doesn't like the prefix) when using prefix mode. Any tips appreciated.

Tobias
- 16th March 2013, 01:19
I did get it working. The one thing that was kicking my ass if I remember right was the True/False for BigEndian.


AStream.InitializePrefix(Main.serial1.InputStream, True, Main.serial1.OutputStream, "AStream")

Also I had to look around to set the BPS right. I am sending at 9600 currently


Incoming= BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1")

Here is the PBP side of the Bluetooth TX


Send_BT: 'Sends data assembled from control boards and outputs to the XOOM
RPM1R=RPM1R+1000
RPM2R=RPM2R+1000',2
RPM3R=RPM3R+1000'1
RPM4R=RPM4R+1000'0
RPM5R=RPM5R+1000
RPM6R=RPM6R+1000
RPM7R=RPM7R+1000
RPM8R=RPM8R+1000
RPM9R=RPM9R+1000
RPM10R=RPM10R+1000
RPM11R=RPM11R+1000
RPM12R=RPM12R+1000
RPM13R=RPM13R+1000
RPM14R=RPM14R+1000
RPM15R=RPM15R+1000
RPM16R=RPM16R+1000
RPM17R=RPM17R+1000
RPM18R=RPM18R+1000
RPM19R=RPM19R+1000
RPM20R=RPM20R+1000
RPM21R=RPM21R+1000
RPM22R=RPM22R+1000
RPM23R=RPM23R+1000
RPM24R=RPM24R+1000
Prefix1=248
Prefix2=0
Prefix3=0
Prefix4=0
RadarTotal=radartotal+1000
debug Prefix1,Prefix2,Prefix3,Prefix4,"R,",dec4 RadarTotal,",",dec4 RPM1R,",",dec4 RPM2R,",",dec4 RPM3R,",",dec4 RPM4R,",",dec4 RPM5R,",",dec4 RPM6R,",",dec4 RPM7R,",",dec4 RPM8R,",",dec4 RPM9R,",",dec4 RPM10R,_
",",dec4 RPM11R,",",dec4 RPM12R,",",dec4 RPM13R,",",dec4 RPM14R,",",dec4 RPM15R,",",dec4 RPM16R,",",dec4 RPM17R,",",dec4 RPM18R,_
",",dec4 RPM19R,",",dec4 RPM20R,",",dec4 RPM21R,",",dec4 RPM22R,",",dec4 RPM23R,",",dec4 RPM24R,",",dec4 RPM1R,",",dec4 RPM2R,_
",",dec4 RPM3R,",",dec4 RPM4R,",",dec4 RPM5R,",",dec4 RPM6R,",",dec4 RPM7R,",",dec4 RPM8R,",",dec4 RPM9R,",",dec4 RPM10R,_
",",dec4 RPM11R,",",dec4 RPM12R,",",dec4 RPM13R,",",dec4 RPM14R,",",dec4 RPM15R,",",dec4 RPM16R,",",dec4 RPM17R,",",dec4 RPM18R,_
",",dec4 RPM19R,",",dec4 RPM20R,",",dec4 RPM21R,",",dec4 RPM22R,",",dec4 RPM23R,",",dec4 RPM24R,",","E"
'serout2 lcd,16468,[Prefix,CursorPS,0,dec RPM1T,",",dec RPM2T,",",dec RPM3T,",",dec RPM4T]
Return

Here is the Bluetooth RX side on the Xoom/B4A


Sub AStream_NewData (Buffer() As Byte)
'Log( BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1"))
Dim Incoming As String
Dim Start As Int
Dim Stop As Int
'sAmount As Int
'LogMessage("INTERFACE", BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1"))
Log( BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1"))
Incoming= BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1")
Start = Incoming.IndexOf("R")
Stop = Incoming.IndexOf("E")

If ScrId>3 Then
''''''''''
If SimSpeedYN="Yes" Then
MPH = SimSpeed
MaxRPM=(30/PC)*(RS/30)*(MPH)*0.168*(txtMasterPop.text/1000)
txtRPM.Text = NumberFormat(MaxRPM,0,1)
Else
MPH = (Incoming.SubString2(Start +2,Stop -241))
'If MPH>0 Then
MPH=(MPH-1000) '''''''''THis is for hard coded MPH
MPH=Radar/MPH
txtMPH.Text=NumberFormat(MPH,0,1)
MaxRPM=(30/PC)*(RS/30)*(MPH)*0.168*(txtMasterPop.text/1000)
txtRPM.Text = NumberFormat(MaxRPM,0,1)
'MPH="0"
'txtMPH.Text=0
' Else
' MPH="0"
' txtMPH.Text=0
' txtRPM.Text = 0
'End If
End If

Log("MPH " & MPH)
If EPD>0 Then
If MPH>0 Then
Row1 = (Incoming.SubString2(Start +7,Stop -236))
Row2 = (Incoming.SubString2(Start +12,Stop -231))
Row3 = (Incoming.SubString2(Start +17,Stop -226))
Row4 = (Incoming.SubString2(Start +22,Stop -221))
txtRow1.Text = NumberFormat(((Row1-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2)
txtMR1.Text= NumberFormat((((txtRow1.Text*1000)/txtMasterPop.Text)),1,3)
txtRow2.Text = NumberFormat(((Row2-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2)
txtMR2.Text= NumberFormat((((txtRow2.Text*1000)/txtMasterPop.Text)),1,3)
txtRow3.Text = NumberFormat(((Row3-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2)
txtMR3.Text= NumberFormat((((txtRow3.Text*1000)/txtMasterPop.Text)),1,3)
txtRow4.Text = NumberFormat(((Row4-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2)
txtMR4.Text= NumberFormat((((txtRow4.Text*1000)/txtMasterPop.Text)),1,3)
Else
txtRow1.Text=0
txtMR1.Text=0
txtRow2.Text=0
txtMR2.Text=0
txtRow3.Text=0
txtMR3.Text=0
txtRow4.Text=0
txtMR4.Text=0
End If
Dim MPHTest As Short
MPHTest=0
txtMPHZ.Text=MPHTest
End If
If EPD>1 Then
Row5 = (Incoming.SubString2(Start +27,Stop -216))
Row6 = (Incoming.SubString2(Start +32,Stop -211))
Row7 = (Incoming.SubString2(Start +37,Stop -206))
Row8 = (Incoming.SubString2(Start +42,Stop -201))
txtRow5.Text = NumberFormat(((Row5-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2)
txtMR5.Text= NumberFormat((((txtRow5.Text*1000)/txtMasterPop.Text)),1,3)
txtRow6.Text = NumberFormat(((Row6-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2)
txtMR6.Text= NumberFormat((((txtRow6.Text*1000)/txtMasterPop.Text)),1,3)
txtRow7.Text = NumberFormat(((Row7-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2)
txtMR7.Text= NumberFormat((((txtRow7.Text*1000)/txtMasterPop.Text)),1,3)
txtRow8.Text = NumberFormat(((Row8-1000)/(((30/PC)*(RS/30)*MPH*0.168)*10)),0,2)
txtMR8.Text= NumberFormat((((txtRow8.Text*1000)/txtMasterPop.Text)),1,3)
End If
end sub


To make sure I was calculating the Prefix right I found this website that allowed me to type in data and it would calculate the size for me
http://mothereff.in/byte-counter

spcw1234
- 16th March 2013, 02:01
Thank You! I will plug away at this and see if I can get it to work.

spcw1234
- 24th March 2013, 16:32
I can't get this to work :( Hoping you can help me! When I run this very simple android program with prefix I get an almost immediate error "Unfortunately, Bluetooth Example has stopped" and the program closes. I am using the Bluetooth chat example to simply display my data in the chat window. I have very limited serial communication experience. With the prefix disabled I get the data as expected, so the communication is good.

This is the Android routine where I switch between prefix or no prefix mode.


Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("2")
If AStream.IsInitialized = False Then
AStream.InitializePrefix(Main.serial1.InputStream, True, Main.serial1.OutputStream, "AStream")
' AStream.Initialize(Main.Serial1.InputStream, Main.Serial1.OutputStream, "AStream") 'NO PREFIX MODE
End If
txtLog.Width = 100%x
End Sub


I tried a few variations here with no luck


Sub AStream_NewData (Buffer() As Byte)
LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
' Incoming= BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1")
' LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1"))
End Sub


My code on an 18F4620 with internal 8mhz osc. I assume I have the prefix correct.


define DEBUG_REG PORTC
define DEBUG_BIT 6
define DEBUG_BAUD 9600
define DEBUG_MODE 0

A1 var byte
A2 var byte
A3 var byte
A4 var byte
prefix1 var byte
prefix2 var byte
prefix3 var byte
prefix4 var byte

A1=11
A2=22
A3=33
A4=44

Prefix1=23 'http://mothereff.in/byte-counter 11,22,33,44,11,22,33,44
Prefix2=0
Prefix3=0
Prefix4=0

main:
pause 1000
debug Prefix1,Prefix2,Prefix3,Prefix4,dec2 A1,",",dec2 A2,",",dec2 A3,",",dec2 A4,",",dec2 A1,",",dec2 A2,",",dec2 A3,",",dec2 A4
pause 1000
goto main

end

Tobias
- 25th March 2013, 02:42
Use this line

AStream.InitializePrefix(serial1.InputStream, False, serial1.OutputStream, "AStream")

instead of

AStream.InitializePrefix(Main.serial1.InputStream, True, Main.serial1.OutputStream, "AStream")

The False part I bet fixes your problem.

spcw1234
- 8th April 2013, 12:22
Use this line

AStream.InitializePrefix(serial1.InputStream, False, serial1.OutputStream, "AStream")

I finally found time this weekend to play with this some more and did get it working! Thanks for your help Tobias!

spcw1234
- 8th April 2013, 13:35
My very simple working code:



OSCCON=%01110000 ' SET TO 8 MHZ internal oscillator
DEFINE OSC 08 ' 8MHZ clock speed
DEFINE HSER_BAUD 9600 ' Set baud rate
DEFINE HSER_RCSTA 90h
DEFINE HSER_CLROERR 1 ' Clear overrun error upon
DEFINE HSER_TXSTA 24h ' Set transmit status and control register
DEFINE HSER_SPBRG 51 ' 9600 Bauds

RPM var word
SPEED var word
TPS var byte
volts var byte
adc1 var word
adc2 var word
prefix1 var byte
prefix2 var byte
prefix3 var byte
prefix4 var byte

rpm = 3800
speed = 60
tps = 10
volts = 122
ADC1 = 512
ADC2 = 200
Prefix1 = 22
Prefix2 = 0
Prefix3 = 0
Prefix4 = 0

main:
pause 500
hserout [Prefix1,Prefix2,Prefix3,Prefix4,dec5 rpm, dec3 speed, dec3 TPS, dec3 volts, dec4 adc1, dec4 adc2]
goto main

end




Sub Process_Globals
Dim AStream As AsyncStreams
Dim Incoming As String
Dim RPM As Int
Dim SPEED As Int
Dim TPS As Double
Dim VOLTS As Int
Dim ADC1 As Int
Dim ADC2 As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("2")
If AStream.IsInitialized = False Then
AStream.InitializePrefix(Main.Serial1.InputStream, False, Main.Serial1.OutputStream, "AStream")
End If
Update_Display
End Sub

Sub AStream_NewData (Buffer() As Byte)
Log( BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1"))
Incoming = BytesToString(Buffer, 0, Buffer.Length, "ISO8859_1")

RPM = (Incoming.SubString2(0,5))
SPEED = (Incoming.SubString2(5,8))
TPS = (Incoming.SubString2(8,11))
VOLTS = (Incoming.SubString2(11,14))
ADC1 = (Incoming.SubString2(14,18))
ADC2 = (Incoming.SubString2(18,22))

Update_Display
End Sub

Demon
- 8th April 2013, 16:00
Thanks for the working example. Can you explain the complete setup? That HSEROUT goes to what, an external bluetooth module?

This would make an excellent article with some narrative explaining what is going on, hardware/software requirements, etc.

Robert

spcw1234
- 8th April 2013, 20:09
The hserout goes to a RN42 bluetooth modem (https://www.sparkfun.com/products/10269). Could be done with debug as shown in an earlier post. Once paired it isn't much different than any other serial connection, but the Android side of things takes some time to wrap your head around. The prefix is a pain, but works very well once working. It is basically just a 32 bit header detailing the number of bytes in the serial string.

Demon
- 8th April 2013, 21:20
Can we control to what device we want to talk to via that header?

Let's say to transmit one thing to my cell phone and another to my daughter's?

spcw1234
- 8th April 2013, 23:13
No, what you transmit to is strictly set by pairing the 2 devices which is not part of this code. I don't think you can pair more than 2 devices. The header is just for validation of the data. The data received flag isn't raised until all data is received, without it the flag is raised as soon as data appears, and then you have to manually put the bytes into a string and wait until they all arrive.

Tobias
- 9th April 2013, 03:23
Good to hear you got it sorted out.

I have to say if you are turning 3800 at 60MPH, you might need to look at changing rear gears :)


I finally found time this weekend to play with this some more and did get it working! Thanks for your help Tobias!

Charlie
- 19th April 2013, 20:09
Just thought I should bring this thread up to date... In the end I gave up on the alternatives, and I broke down and bought Basic4Android since it seems to be the most mature thing out there. If anybody is interested in a 50% off coupon code, you can use this " dqqshs " You go to their purchase page and hit the "Plimus" button, then enter the code.

Demon
- 19th April 2013, 23:51
I'm debating which version to get, Enterprise $99 at 50%?

Bang for buck looks good.

Which are you getting?

(Just checking so I can copy your code :D )

Robert

Demon
- 20th April 2013, 01:43
No, what you transmit to is strictly set by pairing the 2 devices which is not part of this code. I don't think you can pair more than 2 devices. The header is just for validation of the data. The data received flag isn't raised until all data is received, without it the flag is raised as soon as data appears, and then you have to manually put the bytes into a string and wait until they all arrive.

So let's say I have 2 garage door openers, I could pair with the phone, send that header and data defining if PIC should activate relay for left or right door button and then unpair phone?

Just making sure I can get 2 phones to be able to open either door (project #1).

Robert

Charlie
- 20th April 2013, 09:59
Hi Robert - don't feel concern about using the code I posted; they are happy to have people use it. It only works on "Enterprise" though, I'm pretty sure.

The Bluetooth pairing with different devices is more a function of the module you use, I think. I've got a handful of cheap modules from offshore that I'm using with various PIC projects. you basically SERIN / SEROUT to the module and use the module like a serial port. I have paired/unpaired the same module to my development PC, my phone, and my old laptop, so it should happily do what you want. I'll dig back through my notes and post the device number if you wish.

Demon
- 20th April 2013, 13:01
Yup, please, more info is good. :)

Charlie
- 20th April 2013, 18:35
Here you go:
Bluetooth Module (http://dx.com/p/jy-mcu-arduino-bluetooth-wireless-serial-port-module-104299)

Tobias
- 21st April 2013, 09:35
I use the Roving Network bluetooth device. RN-42.

It is pretty easy to use. I downloaded a serial port emulator for my android phone to configure it. Once I realized how the get the emulator to send the correct end of line character, it was pretty easy. The RN-42 allows you to rename the module, set BPS and a few other variables pretty easily.

On the B4A side, the online support is great. Their forum is very active and there are a bunch of other developers willing to help you sort out a problem.

Here are a couple of screen shots.

http://www.grahamelectricplanter.com/Screenshot_2013-01-05-20-08-52.png

http://www.grahamelectricplanter.com/Screenshot_2013-01-07-20-04-55.png

I initially was using a Motorola Xoom and because of supply problems now use a Samsung Galaxy. Everything still works great.

I will say the screen designer could use some touch up. Some basic, no pun intended...get it we are dealing with software called Basic for Android :), is lacking. When setting up a screen you will be able to copy/paste yet not undo. I highly suggest 'Saving' the screen often. Other than that, it helped me quickly get an Android app going communicating with my PIC board.

spcw1234
- 23rd April 2013, 02:20
So let's say I have 2 garage door openers, I could pair with the phone, send that header and data defining if PIC should activate relay for left or right door button and then unpair phone?

Just making sure I can get 2 phones to be able to open either door (project #1).

Robert

The only problem I see here is that it takes 30 seconds to pair up every time, might be able to do it faster but I haven't figured it out. That might not be a big deal, but not as simple as a normal garage door opener.

Demon
- 23rd April 2013, 13:11
30 seconds would indeed suck. :(

ardhuru
- 28th June 2013, 13:13
After wrapping my brain around the problem, I finally stumbled across this thread.

I am trying to almost exactly the same thing; display a packet of 6 bytes spit out by the pic on an Android, using B4A in 6 different boxes.

The B4A side of things is completely unchartered territory for me; just figured out the advantages of using the prefix mode.

Now, I have a few questions; Shawn, in post#16, you have defined the prefix length to 22. But the decimal digits add up to 25. How is that?

As I said, my expertise on B4A is extremely mediocre; could you please show us the complete code on that side? For example, I am unclear (PLEASE forgive my complete ignorance, I suspect this is quite straightforward) how to fill up individual labels with the incoming data bytes from your Update_Display routine.

Thanks!

Anand

ardhuru
- 28th June 2013, 15:35
in post#16, you have defined the prefix length to 22. But the decimal digits add up to 25. How is that?



Sorry, my mistake about the prefix length.

Still struggling with the other aspect, though..