Using Arduino libraries

Discussion of issues related to writing ZBasic applications for targets other than ZX devices, i.e. generic targets.
Post Reply
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Using Arduino libraries

Post by dlh »

With generic devices, can we link to Arduino libraries?

Can we create object files? I have some code covered by an NDA that I need to hide.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Using Arduino libraries

Post by dkinzer »

dlh wrote:With generic devices, can we link to Arduino libraries?
Firstly, it is important to note that Arduino "libraries" are not object libraries that can be incorporated into an application at link time. Rather, they are collections of source code that the Arduino IDE causes to be compiled along with your application code. The object files resulting from that compilation are then linked together with the standard C/C++ libraries to produce an executable image.

If you have an Arduino "library" that doesn't use any of the Arduino core functions (e.g. millis(), digitalWrite(), etc.) then it can probably be made part of a ZBasic application whether targeted to a ZX or a generic AVR device.

For Arduino "library" code that does use Arduino core functions (many of which provide the same or similar functionality as ZBasic System Library routines), you would need some interface code that implements the Arduino core functions in a manner that is compatible with ZBasic.

I have successfully used the Arduino Ethernet "library" code to add Ethernet connectivity to a ZBasic device both using an Arduino Ethernet Shield and using a vanilla Wiznet W5100 module. To achieve this I created a ZBasic/Arduino interface layer that provides all of the capabilities of the Arduino core code (found in the hardware/arduino/cores/arduino subdirectory of the Arduino installation directory). Some of the Arduino core files were used directly without modification, some needed slight modification and others were replaced completely.

I am in the process of writing an application note on the use of the ZBasic/Arduino interface code that will describe the issues that might arise and how they might be addressed. A second application note is planned describing the use of the Arduino Ethernet "library".
dlh wrote:Can we create object files? I have some code covered by an NDA that I need to hide.
Yes. The easiest way is to create an object library (a .a file) and distribute that. See Section 6.7 of the ZBasic Language Reference Manual.

I've added a post to the Files forum with a simple example of creating a library.
- Don Kinzer
stevech
Posts: 715
Joined: 22 February 2006, 20:56 PM

Post by stevech »

WizNet 5100 code.. in ZBasic? Mind sharing it?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

stevech wrote:WizNet 5100 code.. in ZBasic? Mind sharing it?
The ZBasic code is just a wrapper over the Arduino Ethernet "library" code. Consequently, the ZBasic/Arduino core code is needed, too. I'm planning to write one application note on the ZBasic/Arduino core code and a second one on using Arduino "libraries" with the Ethernet as an example. Code will be included with both.
- Don Kinzer
stevech
Posts: 715
Joined: 22 February 2006, 20:56 PM

Post by stevech »

Ah.
I have WizNet 5100 C code for UDP, TCP, FTP client, and so on. The WizNet example code was not used because my code needed to be interrupt driven for all 4 sockets, so there'd be no looping. I started on a translation the C code to ZBasic long ago, but decided that most AVRs just don't have enough RAM, though the large-ish buffers in the W5100 chip can be used cleverly, e.g., leave the data there until you are ready to copy/process the next small hunk using AVR RAM.

I had some challenges with the 5100 chip... Lacks adaptive TCP ACK timeout and adaptive TCP window size - needed for cellular. It was a bear to do this, until I finally disabled windowing to prevent TCP timeouts and retransmissios by the other end. I also wired up one of the RJ45 Link-LED bits to the software could "see" if the media is disconnected or the far end switch is off. Else packets just build up in the W5100 buffer with no viable way to know why.

Next go-round, I'd look at their newest chip that again supports SPI. Their successor to the 5100 didn't.


So it's working well, with these and other subtle lessons learned, for an app that just has to run 24/7 unattended (100 sites).
Post Reply