Connecting eb500 to bx24 HELP

Started by femme_pacita December 2, 2007
Hi, I read you know something about connecting the bx to the bluetooth
device. Coulyou please help me? I've been researchin for some days now
and I still don't know how to finish my proyect. Our deadline is
aproaching and I would really appreciate some help.

I know how to connect phisically the micocontroller to the eb500, but
I dont know how to make the bx24 order the eb500 to connect to another
bluetooth in a computer and to send data out by the eb500

Have any idea how the code would look like?? please???
> ... connect to a pc bluetooth?

One end needs to find the other, a process called pairing. You must
usually tell one of the radios to allow pairing, then direct the other
to find it. I would opt to have the PC find the EB500, but you can do
it the other way; that's up to you and convenience. You'll need to find
the appropriate commands in the EB500 manual and send those commands
from the BX-24, perhaps using a different BX-24 program (once done,
pairing usually sticks) unless the pairing needs to happen each time you
start the project up - like if the PC is not always the same one.

ACK is short for Acknowledged, NAK for Not Acknowledged. If you send a
valid command the EB500 it will send an ACK, otherwise a NAK. It's a
crude comm validation method.

Read that manual!
Tom
Yup, your code compiled and ran fine. I added an OpenCom1 so the the
loop output would be easily visible in the IDE:

Option Explicit
Public Sub Main()
dim ibuffer as byte
dim obuffer as byte
dim q1 (1 to 160) as byte
dim q2 (1 to 160) as byte

Call DefineCom3(16, 17, bx1011_0111)
Call OpenQueue (q1, 160)
Call OpenQueue (q2, 160)
' Call OpenCom (3, 19200, q1, q2)
Call OpenCom (1, 19200, q1, q2)

Debug.print "bluetooth"
Do
Call PutQueueStr (q2, "funcion whatever")
Loop
End Sub

*** Opening file: C:\Program Files\BasicX\Project1.bxb
*** Downloading File
Writing internal EEPROM
Verifying internal EEPROM
Verify OK
Writing external EEPROM
Verifying external EEPROM
Verify OK
*** Finished Downloading
bluetooth
funcion whateverfuncion whateverfuncion whateverfuncion whateverfuncion
whateverfuncion whateverfuncion ...

I question only the size of the queues. You only have 401 bytes of RAM
to work with in the BX-24, you've allocated 320 for the queues alone,
and you also need some for other variables and stack. There is not much
left.

You only need as much queue as you need to buffer, i.e. if the source
sends in bursts of 10 bytes and you only take it from the queue in
single bytes, you need at least 10 bytes (plus nine bytes of overhead
for each queue), so that queue must be 19 bytes total or you might miss
some input data. Similarly, if you need to send a single variable of,
say, 20 bytes, you need at least a 29-byte output queue, but much more
is probably wasted RAM. Note that, if you put something to a queue that
is longer than the queue, the program will hang at that point, forever
waiting for sufficient space.
> BX-24 serial comm is easy. You must OpenQueues of sufficient lengths
> for input and output data and, if using COM3, Define it's parameters,
> then OpenCOMn. Data is sent with PutQueue and received with GetQueue.
> See the Basic-X manual and look at many examples in
>
http://tech.groups.yahoo.com/group/basicx/files/Datasheets-Appnotes-Examples-Dra\
> wings/Comm/
>
> Tom
>
Tom, thanks a lot. That was REALLY usefull. I understand how to define
and open com3 and to open the queues, can you please help me write the
code to make the eb500 find and connect to a pc bluetooth?

By the way, I didn't understood the "and ACKs or NAKs the command"
part. Sorry, kindda new at this.
> ... when I tell the bluetooth in the pc to detect the other one, it
only finds a COM5...

That's probably correct. COM5 is the _PC_ COM5, a logical port assigned
to _its_ Bluetooth device. COM5, on the PC, is the port you must use to
talk to the remote radio. Try running a terminal program on the PC and
look at COM5.
Now I'm puzzled. Is your intent to have the PC play a note that
corresponds to a distance determined by the BX-24? Or have the BX-24
drive a MIDI hardware channel, connected to a synth that plays the
note? If the latter you must use COM1 and some additional hardware
(conventional MIDI is a current loop) to be MIDI-compatible.

If that's so, the MIDI output (at ~31kbs) must be on COM1 since COM3
can't operate above 19200, and you'll need to convert that COM1 data
to current loop. Here, you open COM3 and you send MIDI output to COM3
at 9600. That won't work unless the PC (tied to BX-24 COM3 via
Bluetooth) passes the MIDI along to a synth or equivalent.

If your intent is to play the note on the PC via Bluetooth, you don't
need 31kbs; you can use any speed, I think, to get the MIDI data to
the PC and then pass that along to a true MIDI hardware output like
those available on many sound boards, or a software synth. The latter
will require some PC programming, perhaps a VB application that takes
serial Bluetooth data and controls a software synth via DirectX, I
believe.

The register.ubrr = 14 line can only affect the hardware UART on COM1.
It will have no effect on COM3, which is a software UART.

> 'open serial port on COM1:
> Call DefineCom3(16, 17, bx1011_0111)
> call openCom(3, 9600, inputBuffer, outputBuffer)
>
> 'set baud rate to 30.270:
> register.ubrr = 14
That's exactly what I want, my bx sending out MIDI, but I don't know
how to translate the data recieved into sound or how to send it into
the MIDI board

I managed to send text and visualize it with HyperTerminal, but
nothing more.
> ... I want my bx sending out MIDI, but I don't know how to translate
the data received into sound or how to send it into the MIDI board...

If the goal is to generate sound you can look into the BX-24 PlaySound
procedure to drive a speaker with the BX-24 directly, but I have no
experience with it. Perhaps someone else here can help.

If the exercise is to use MIDI, you have two choices: convert COM1 to
a MIDI current-loop interface and connect it to a synth with a 5-pin
MIDI cable, or write a VisualBasic or other PC language program to
receive the MIDI data via Bluetooth and control a synthesizer
connected to the PC. If that's the task, you'll need to switch hats
now and become a PC programmer.

Tom
Ok, I added my program to the code. This s it

dim outputBuffer(1 to 10) as byte '1-byte output buffer
dim inputBuffer(1 to 13) as byte '1-byte input buffer
'declare an array of 12 byte variables

dim pitch (0 to 11) as byte

'declare other vriables
dim note as byte
dim ADCvar as integer
dim ADCvar1 as integer
dim midiCmd as byte
dim velocity as byte

Sub Main()
'the 12 elements of the array called pitch are the 12 notes of a scale:
pitch(0)= 60 ' middle C
pitch(1)= 36
pitch(2)7
pitch(3)8
pitch(4)d
pitch(5)e
pitch(6)f
pitch(7)g
pitch(8)h
pitch(9)i
pitch(10)p
pitch(11)q
'open serial queques:
call OpenQueue(inputBuffer,13)
call OpenQueue(outputBuffer,10)

'open serial port on COM1:
Call DefineCom3(16, 17, bx1011_0111)
call openCom(3, 9600, inputBuffer, outputBuffer)

'set baud rate to 30.270:
register.ubrr = 14
do
call putpin(25, 0)

'my distance ranger gave a range from 0 to 1024
ADCVar=getADC (13)
ADCVar1=getADC (15)
'convert to range from 0 to 11:
'note = cByte(ADCVar \ 98)
if ADCvar=0 then
if ADCvar1=0 then

'sent a note on message, channel 1, velocity 64:
midiCmd = &H90
velocity = &H64
call putQueue(OutputBuffer, midiCmd, 1)
call putQueue(OutputBuffer, pitch(3), 1) 'pitch[note]
call putQueue(OutputBuffer, velocity, 1)
call delay(0.25)
midiCmd = &H80
velocity = 0
call putQueue(OutputBuffer, midiCmd, 1)
call putQueue(OutputBuffer, pitch(3), 1) 'pitch[note]
call putQueue(OutputBuffer, velocity, 1)
call delay(0.03)
end if
end if
if ADCvar=0 then
if ADCvar<>10 then
'sent a note on message, channel 1, velocity 64:
midiCmd = &H90
velocity = &H64
call putQueue(OutputBuffer, midiCmd, 1)
call putQueue(OutputBuffer, pitch(1), 1) 'pitch[note]
call putQueue(OutputBuffer, velocity, 1)
call delay(0.03)
midiCmd = &H80
velocity = 0
call putQueue(OutputBuffer, midiCmd, 1)
call putQueue(OutputBuffer, pitch(1), 1) 'pitch[note]
call putQueue(OutputBuffer, velocity, 1)
call delay(0.03)
end if
end if

if ADCvar1=0 then

'sent a note on message, channel 1, velocity 64:
midiCmd = &H90
velocity = &H64
call putQueue(OutputBuffer, midiCmd, 1)
call putQueue(OutputBuffer, pitch(2), 1) 'pitch[note]
call putQueue(OutputBuffer, velocity, 1)
call delay(0.03)
midiCmd = &H80
velocity = 0
call putQueue(OutputBuffer, midiCmd, 1)
call putQueue(OutputBuffer, pitch(2), 1) 'pitch[note]
call putQueue(OutputBuffer, velocity, 1)
call delay(0.03)
end if

Debug.print "bluetooth"

Call PutQueueStr (OutputBuffer, "funcion whatever")

Loop
End Sub
But when I tell the bluetooth in the pc to detect the other ne, it
only finds a COM5, no way to make it look for COM3.
So the pc detects it when I power it, but I can't make it send data out.
> ... You're right about that.

Right about what? I think I asked which of three possibilities you're
trying to do.

> ... the other one receives the midi through the bluetooth and sends
the audio out to a midi board.

You can't send audio to a MIDI board, at least not in the conventional
sense (you can load audio _samples_ to be played as a note by a sampler
via MIDI but I doubt that's what you need to do).

I still don't understand what your goal is. If you _must_ be wireless
and you don't want to or can't program the PC to collect MIDI data from
Bluetooth and operate a PC sound board synth, software synth or external
synth with that data (it is not audio yet, just a string of commands
that a synthesizer will convert to audio), you'll need to receive the
Bluetooth and convert it to MIDI , then sound, another way.

Another Bluetooth radio, and another BX-24 with its COM1 (at ~31250)
tied to the current-loop MIDI interface of a synth will do it, too. One
of the EB500 commands will tell you the Bluetooth MACs of available
radios to pair with; the PC adapter can do the same. You might also
find the MAC printed on a label on or in the EB500 or its box.

Thursday? That's tomorrow where I am. Build a time machine first so
you can give yourself another week; you're late.

Tom