Arduino Library and examples

  • 10
  • Idea
  • Updated 2 years ago
  • (Edited)
Hello,

while I am writing my homebrew Arduino Controller code, I realized that I
could share the basic part of my code for Band Data and CAT usage. I
read some posts on the Community from people asking for a particular kind of Band Data system like I2C, BCD, RS-232 and so on. Waiting for other manifactures to adopt the Flex native ethernet protocols, you could use this library to command already existent devices. This library really doesn't implement a specifica protocol, but give you a very simple way to do it.
The code is open and free and is provided in three parts: a basic library that works at the ethernet level and two library examples that show you how you can use the libraries for band data and CAT purposes.
The software also does not implement any set command but only the commands required from other devices to get the radio status.
So you need to have knoweldge of SmartSDR Ethernet API, SmartSDR Command Line API, Arduino and C programming.

The Basic library is essentially a small piece of software that implements the SmartSDR Discovery Protocol to locate and connect a FlexRig in your network. In default mode the library try to locate the first FlexRig available in the network, then it try to establish a connection using the 4992 Tcp-IP port. This approach is correct if you have only one Flex Rig (like in my case).


If you have more than one Flex Rig on the same network, you have to manually set the serial number of the rig you want to connect to.


When the radio has been located, the library starts a connection over the 4992 TCP/IP port. It is used to command the radio and receive streaming status information. Every update on the internal state of the radio is then reflected on the library objects.


Going more in depth, a parser analyzes the TCP/IP packets, selecting only the Status "S|" one and then pass any updates to the local software objects.

In this way, using the library, you can access the internal state of the rig without having to deal with network protocol.

The library can handle the objects shown in the picture below. As you can see the number of slices, panadapters waterfalls is limited only to two as I did tests only on my Flex-6300. The library can be extended to monitor the status of multiple objects as in the case of 6500 and 6700 Radio. The ATU is also a missing object because my 6300 isn't equipped with it and I have never tested it.

To use the library you need a really powerful micro-controller. I choose Arduino Due because it is very simple to program and has a C standard instructions set. Also you need an Arduino Ethernet Shield that uses the W5100 chip. It is the best board that allows your Arduino to access the network at 100Mb/s. It is also the board that has the best support libraries.


== Banda Data Library Example

Band Data library relies on the previous library and it generates events you can simply handle from inside you sketches. You don't need to worry about basic rig communication, nor you are requested to handle all your logic in the main loop() routine.

Simply, in the setup() procedure, you have to register a function (handler) for each event that you need to handle. The library do the rest.

You can register your code for the following events:

  • Any update on Slice objects (only # 0/1)
  • Any update on Panadapter objects (only # 0/1)
  • Any update on Waterfall objects (only # 0/1)
  • Any update on Radio object
  • Any update on Transmit object
  • Any update on Interlock object

After having registered your event handler, the library execute a call to it, each time that particular event occurs. In the handler routine you can activate your hardware or you can use strategies to monitor your system.

Last but not least, as you can have access to a great number of Flex object properties, you can extend the library code to handle events based on a particular object properties.


=== CAT RS232 Library Example

I have only implemented the commands that can be useful for external devices synchronization, mostly amplifiers and dynamic antennas controller. I do not own any of these devices so I did tests using other software like Omnirig and LOG4om. It seems it works nicely, but be careful, you have to do your own test.
The library also does not implement any set command but only the commands required from other devices to get the radio status.

Below you can see the actual command list:

FA; - Reads Slice receiver A frequency
FB; - Reads Slice receiver B frequency.
IF; - Reads Transceiver Status
FR; - Receive VFO
FT; - Transmit VFO
AI; - Auto Information Mode
ZZFA; - Reads Slice receiver A frequency
ZZFB; - Reads Slice receiver B frequency
ZZIF; - Reads Slice Receiver A DSP filter 


You can find code and examples at the following links:

Basic
Band Data Example
CAT Example

Calling these "library" is a bit pretentious and the purists of the C / C ++ might blame me looking at my code. But it seems the code works and is open. So if you like, you can change and improve it. Just let me know.

Last, I recorded a video to show you how you can use the software.

73' Enzo
iw7dmh

Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes

Posted 3 years ago

  • 10
Photo of EA4GLI - 8P9EH - Salvador

EA4GLI - 8P9EH - Salvador

  • 1747 Posts
  • 532 Reply Likes
Fantastic tutorial. Grazie mille Enzo.
Photo of Steve - KD8QWT

Steve - KD8QWT

  • 74 Posts
  • 14 Reply Likes
Thank you Enzo for sharing this.  Excellent work.  
Photo of Steve W6SDM

Steve W6SDM

  • 622 Posts
  • 280 Reply Likes
Fantastic.  Thanks for the information.  Now I can plan something for my Arduino that doesn't involve turning LEDs on and off.  Thanks!
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
Well, my Arduino controler is nearly ended.
Here is a test in the field during a contact with 5Z0L Kenya Expedition.
It works fabulously with smooth heavy metal vfo and very responsive meters.
Most of SSDR controls are already implemented and of course it works also without a computer.
It is amazing thinking that only 120 Kb of C/C++ code can handle most of the Flex Rig power.

73' Enzo
iw7dmh

Photo of Steve - KD8QWT

Steve - KD8QWT

  • 74 Posts
  • 14 Reply Likes
Very nice.  Have you made any changes to your library?

I'm getting ready to roll out my magnetic loop controller changes this weekend.  It watches the flex and automatically sets the vacuum variable capacitor position.  My project was pretty far along when you posted your library.  I did try it but was getting negative numbers for frequency.  The compiler complained about a missing dtostrf file, which I did find.  Work travel and various other priorities prevented me from looking at it again.  If you've made no changes, then I'll try debugging it this weekend before I no longer have the ethernet shield to test with.  
Photo of Steve - KD8QWT

Steve - KD8QWT

  • 74 Posts
  • 14 Reply Likes
I was using the MEGA 2560.  
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
Ok, so you can compile the code adding a comment to line n. 16 in the library header file FlexRig.h, but it should not solve the negative number issue as ATmega2560 is an AVR 8bit class processor and treats integer in different way .
I don't own any 2560 board so I can't run any additional test. :(
Anyway, also compiling and running well on AVR class board, you should find performance issues as the parsing code is really very heavy.
That is the reason I chose a more powerful ARM board.
(Edited)
Photo of Steve - KD8QWT

Steve - KD8QWT

  • 74 Posts
  • 14 Reply Likes
That probably explains it.  For the application I'm using it for, the mega is performing quite well.  I only parse a few very specific items and only subscribe to slice events.  With the 6300 I only have 2 slices to watch.  For frequency, all I need is 3 decimal places, so I don't need such a large number.  From the time I change the frequency to the time the stepper starts moving is usually well under a second.  My biggest performance issue is waiting for the stepper to traverse the length of the 25 turn capacitor.  For a UI application I can see the need for a faster platform.  For a back end application like a magnetic loop controller, an 8 bit Arduino works just fine.  The best part is I didn't have to deal with c/c++ code.

Thanks to the work you and a few others in this community have done, I think the development of 3rd party apps is going to really start taking off much faster now.  Fun stuff!
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
Please, at the end of your work, consider the idea to share your code.
It could be helpful for other friends that would like to experiment.

73' Enzo
iw7dmh
Photo of Steve - KD8QWT

Steve - KD8QWT

  • 74 Posts
  • 14 Reply Likes
I'll create a separate post on it in the next few days.  It's really nothing much to look at :)

Steve 
Photo of James Whiteway

James Whiteway

  • 862 Posts
  • 187 Reply Likes
Enzo, well done! I will send my pre-order deposit ASAP!
:-)
james
WD5GWY
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
Imagine what can we do with the super-equipped Maestro :)
keep our breath ...
73'
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
Hello,

during my holidays I found the time to update my Arduino libraries.
The main feature is that you can compile it on both AVR (Mega) and ARM (Due) boards.
In addition the library embeds the whole set of event handlers and the basic rig object (fRig) exposes the most important setter methods.
In this way you can interact with the rig without having to deal with the underlying Ethernet APIs. Anyway it is required a very good knowledge of the FlexLib Apis.

I hope this can help.

73' Enzo
iw7dmh
(Edited)
Photo of Steve - KD8QWT

Steve - KD8QWT

  • 74 Posts
  • 14 Reply Likes
Excellent news.  Thank you!
Photo of philip.theis

philip.theis, Elmer

  • 111 Posts
  • 19 Reply Likes
Enzo,
Hi, I am also grabbing band data and sending it to GPIO and I2C using a BeagleBone Black.
I was going to look at your code but the Band Data Example does not exist on the link above.
Was it removed?
thanks,
Phil K3TUF
Photo of pa0bie

pa0bie

  • 152 Posts
  • 20 Reply Likes
I also could not find the Band Data Example.
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
As I pointed before, Band Data code is embedded in the library.
In my answer to Phil, K3TUF, you can see som usage example.

73' Enzo
iw7dmh
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
@Dave,VA3AE

>...
>I expected to see some events as I changed things on the FLEX-6500, but i do not
>...

The log you have dumped confirm that your board can connect your Rig. well done :)
To see the events please follow the example I posted above (read my answer to Phil, K3TUF).
Consider that, using the FlexSignature.ino, all the events are already implemented but they are also commented. This saves a lot of memory and you only need to comment out the handler you need: band, frequency, mode, and so on.

Test01.ino is intended for connection test purpose only.

73' Enzo
iw7dmh
(Edited)
Photo of Jay / NO5J

Jay / NO5J

  • 1466 Posts
  • 219 Reply Likes
Jon 
With the SDR1000 all that is really needed is a device that ouputs the control signals as a parallel port would. PCI/E parallel port cards work. USB-parallel cables don't, with the exception of the Flexradio USB/IO cable that looks like it's just a USB adapter cable, but contains some additional hardware.
The SDR1000 is not a printer.

Another complication is that PowerSDR expects to be connected to either a real parallel port, or the Flex USB/IO device.

A further complication is that Microsoft no longer supports this sort of communication in 64 bit versions of Windows. CNC machines also used this setup between computer and CNC machines. and are having similar problems with 64bit windows.

I'm really just curious if an Arduino might be the solution since it might be possible to program it's input and output to emulate a USB/IO device. PowerSDR and DTTSP are open source so it might be possible to reverse engineer a solution.

I sort of hoped Enzo's reply would be "Of course it can, been there done that. 

That Elecraft Band Decoder interests me for other projects though.
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
Enzo
Do you know if an arduino could be used to provide the control signals the PowerSDR and the SDR1000 send over the parallel port. I'd love to find a way to communicate with my SDR1000 without 32bit windows and a PC parallel port. Sorry, if this turns out to be a dumb question.
73, Jay - NO5J

Virtually you can implement any logic in a Arduino board.
A band decoder project usually requires an input line from the rig and one or more output lines for third part devices.
If your idea is avoid a 32bit windows pc you need to implement the CAT protocol in the Arduino board. For this purpose things are more complicated as you need a USB host shield and a USB-RS232 adapter: in this scenario the Arduino board is a host device and you cant' use the standard RS232/USB port (that is a client port).
On the output side, instead, you can use any of the output ports to drive the DB25 lines.

73' Enzo
iw7dmh
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
Hello,

I would like to point out that the library project is developed using genuine or compatible arduino.cc products (and its related sw libraries).
This clarification is necessary because it could happen you buy accidentally products from the arduino.org line that could not work properly with my FlexRig code.
Of course my library is open and you can change it as you like, but using .org products I can't give you a great support.
This is the negative effect due to Arduino splitting event.

73' Enzo
iw7dmh
(Edited)
Photo of Steve - KD8QWT

Steve - KD8QWT

  • 74 Posts
  • 14 Reply Likes
Apparently the Due from arduino.cc is now discontinued.  Another effect of the split.

Any chance the libraries can work on arduino.org or the clone boards?
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
Hello Steve,

I didn't tested any .org Due board, but it should be.
I am sure, instead, that the Ethernet shield 2, from .org, is working very well with my libraries. Some friends are using it with success.
I wouldn't bet a penny on clone boards because, up today, I had only bad experiences.

73 Enzo
iw7dmh
Photo of Steve - KD8QWT

Steve - KD8QWT

  • 74 Posts
  • 14 Reply Likes
I'm using the .org Due and ethernet shield for another project.  I couldn't find any .cc boards when I purchased them.  So far I haven't had any issues with either one.  It has been able to handle gpredict, serving a web page, and telnet sessions at the same time.  It's probably not the same amount of traffic as the Flex API, but there is a lot going on with other sensors and such.  Overall I've not had any issues that weren't of my own making.

I'll try to do some testing with the Flex libraries in the next couple weeks.
Photo of David Scobie

David Scobie

  • 18 Posts
  • 1 Reply Like
Hi Enzo, I've tried a number of coding experiments over the last week, and done a fair bit of reading, of the FLEX Documents and on the sometimes unpredictable characteristics of the Mega2650.
If this work can help some others, then this week's effort will be worth it to me. Here is what I have learned:
If I understand correctly, certain patterns contained in my compiled Hex code are mis-interpreted by the bootloader as reserved instructions, or maybe it's just jibberish.
This happens when I perform the standard upload via USB/UART port.  
Accordingly, I can bypass that and use the ISP/ICSP (In Circuit System Programmer)  or as I learned in College <To connect directly to the board and Whack the device with raw code>.

Now, I have several parameters to pass to avrdude to get it to behave:
bin/avrdude -C%ProgramFiles(x86)%\Arduino\hardware\tools\avr/etc/avrdude.conf -vvvv -patmega2560 -cusbasp -Uflash:w:%HOMEPATH%\appdata\Local\Temp\build8021697898052857256.tmp/sketch/FlexSignature.cpp.hex:i

This seems to get the code into the device reliably, and I make sure it erases the flash and does a verification pass on each upload of about 82K - Lots of free space remains.  Of course the %BUILD-DIR% changes every time we recompile, but alas, such is the world of Micro$oft.

Next, I have tried several calls to events using your nicely organized layout.  I've concentrated on G06_RadioEvents and G12_SliceEvents. My other Arduino Program/Hardware will parse that output and use it as input to instruct the hardware to tune the antenna stepper/SWR measuring system and to toggle a set of 9 relays to switch control lines and coax feeds.  Eventually I will watch for events and potentially even issue commands in special conditions.  This all works now via CAT over serial but the Ethernet control is required for the Flex.

Unfortunately I have not been able to make the FlexSignature.cpp.hex return any values for configured slice events - onRadio_slices - onSlice_RF_frequency or even onSlice_in_use.  I've defined and uncommented the relevant sections.  I've checked the code several times and even started again from the beginning with a fresh untar to make sure I hadn't unintentionally shot myself in the foot.

 I receive in the serial monitor the connect, the version, the Handle and the message "==>LISTENING FOR VITA49 PACKETS"
However nothing seems to be returned when I change parameters an the radio.

There is also still an unexpected letter _c after the Nickname, and I admit I am still puzzled why I don't get a proper "hello world" from the Arduino.  
At this point I am thinking that the Mega2650 is just not the piece for this job; it has quirks and this may be a demonstration of that nature. 
I've thought of trying to run the code in an emulator and tracing but I haven't had time to research any of that yet.  The default Arduino IDE is pretty bare bones, it can't even step or breakpoint the code, so I have some more stuff to learn about how to do more advanced troubleshooting.

Enzo, you have had success with the Arduino Due and it may be I would need to go that route to recreate your success. 
It is a bit of a shame that I have spare 2650's that I thought I could put to the task.
Again, if anyone has suggestions, I am all ears.
I paste the output below.
73 de Dave, VA3AE

===========Flex Rig=============
IP Address:192.168.2.165
Model Name:FLEX-6500
Serial:0915-4055-6500-6717
Version:1.4.16.6
NickName:=6500-VA3AE c
connecting to Flex rig:192.168.2.165.
Connected
==VERSION (connect)==
1.2.0.0
==HANDLE (connect)==
A6705F55
==>LISTENING FOR VITA49 PACKETS
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
Hello Dave,

thank a lot for your in depht analysis. I have very low experience on Mega boards, so I need more time to repeat all the test. As I said before I am working on the cat multiplexer project, using just a Mega board. At the end of my work I'll have a better knowledge of the pro and cons Mega boards. Of course I'll share with you any (if any) progress.

73' Enzo
iw7dmh
Photo of K1FR

K1FR

  • 107 Posts
  • 9 Reply Likes
Enzo:   Just wondering if the Arduino.cc WiFi Shield R3 would be equally compatible for these applications with a Due?  Thanks!

73, Tom
K1FR
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
Hello Tom,

wifi shield is currently retired is and will be replaced by Wifi-shield 101
I hope the new libraries will be fully compatible with the ethernet lib so we can simply switch the board an go.

73' Enzo
iw7dmh
Photo of K1FR

K1FR

  • 107 Posts
  • 9 Reply Likes
Thanks, Enzo!  Did not know about the new WiFi.  Sounds interesting though.  Am enjoying fooling around with Arduino stuff again.

73, Tom
K1FR
Photo of Steve - KD8QWT

Steve - KD8QWT

  • 74 Posts
  • 14 Reply Likes
Another option is a wireless bridge.  Most access points can be configured as a bridge, allowing ethernet devices to be plugged into the bridge device which then bridges all the ethernet packets to the main AP.  I have a raspberry pi and Arduino Mega plugged into a wireless bridge.  The pi is an ADS-B receiver and the Arduino is being used as my magnetic loop controller.  All 3 have been sitting outside in a weather proof plastic box.  I went this route because I didn't want to experiment with wifi on the Arduino and I got a free bridge device my ASUS RT-N66U router.
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
Yes Steve, it is.

Using a bridge is a straight solution to have an arduino boards connected to a network via wi-fi.
You can use a bridge also with our recent notebook. If you have windows 7 or more recent operating system you can configure a bridge with few clicks.
It is the way I can move my controller out of the shack.
Here are my notes about configuring a network bridge on Windows 7
Photo of John G3WGV

John G3WGV

  • 180 Posts
  • 35 Reply Likes
Hi Enzo and all you API developers out there. This is my first post to the forum, so be gentle with me :)

I'm a recent "convert" to the world of SDR - my 6500 arrived yesterday afternoon. My plan is to build a custom front panel as, being an old 'un, I can't deal with controlling a radio in contests and pileups solely via mouse clicks. I want tuning knobs and buttons and other things to twiddle!

So I was absolutely delighted to discover Enzo's excellent Flex library. It makes it really easy to rapidly develop a custom Flex control program. A couple of hours after first turning on the radio I had basic VFOA/B tuning working and was displaying frequency and S-meter data. Congratulations, Enzo, on a fine API library.

I already have a few questions regarding the API and, probably, Enzo's library implementation, Should I post these here, or would you prefer me to use e-mail, Enzo?

For example, this is nagging me:

When I use the API to tune onto a CW signal, I hear an irritating cracking sound that seem to be in step with the CW signal and the tuning. When I stop tuning the crackling stops. When there is no signal there is no crackling when I tune. This doesn't seem to happen when I use the mouse wheel to tune but I have noticed it when I click/drag the frequency rapidly across a bunch of CW signals. The effect is not (so) noticeable on SSB.

I'm wondering if this is an artefact of the radio, the API or (unlikely!) Enzo's library.

Right... back to programming my Adruino Due!

73, John, G3WGV
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
Hello John,

I just can say that my libraries, and each other Flex client, use the underlying ethernet connection, so it should be very difficult that the client itself can cause RF artifacts in your speakers.
I would suggest you to do a check of your wire connections, in particular the audio lines and, if needed, to try with RF blocking beads.
From the beginning I am using the very good Bose Companion speakers (suggested by Tim). They have shielded magnets and are totally free from RF interferences, and of course, have a gread audio response.
What speakers are you using?
I would also suggest to consider the incoming Maestro console that is a must-have device for ours rigs. It is actually a great add-on!

73' Enzo
iw7dmh
  
Photo of John G3WGV

John G3WGV

  • 180 Posts
  • 35 Reply Likes
Hi Enzo,

Thanks for your comments.

I don't think it's anything to do with your libraries either. I put a dummy load on the Flex and I still hear the clicks, apparently randomly, as I tune. I am listening using headphones plugged directly into the 6500 front panel. So it's a bit of a mystery.

Am I right that the only way to tune the band is to send full frequency updates? There seems to be no step up/down by, say, 10Hz in the command API. That means that if I tune quickly I'm sending hundreds of full frequency QSYs to the radio each second as I tune up the band. I'm wondering if the 6500 is objecting to this, as I don't notice the clicks if I tune very slowly.

I saw the Maestro and it looks very nice but I like the idea of experimenting and building my own custom controller.

73, John, G3WGV
Photo of IW7DMH, Enzo

IW7DMH, Enzo

  • 353 Posts
  • 84 Reply Likes
So enjoy with your test.
Sometimes it could be exiciting but sometimes it could be frustrating ... :)
BTW I can confirm there isn't ad +/- fixed band increment command, and you have to simulate it using your own code.

73' Enzo
iw7dmh