# Help wrapping Arduino Libraries

**URL:** <https://forum.xod.io/t/help-wrapping-arduino-libraries/3217>\
**Category:** XOD Programming Questions\
**Created:** [January 7, 2020, 4:38pm UTC](https://forum.xod.io/t/help-wrapping-arduino-libraries/3217 "2020-01-07T16:38:56Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [January 7, 2020, 4:38pm UTC](https://forum.xod.io/t/help-wrapping-arduino-libraries/3217/1 "2020-01-07T16:38:56Z")

</div>

Trying to write a XOD wrapper for [GitHub - tve/lx16a-servo: Simple ESP32-Arduino library to operate LX-16A serial servos](https://github.com/tve/lx16a-servo)

The 1st issue is that they put header files in a src sub-folder & XOD cannot find it. I’ve tried using #include \<src\LX16AServo.h\> instead of just #include \<LX16AServo.h\>, but that does not help. My short-term fix is to copy the .h & .cpp files up one folder so XOD can find them.

The 2nd issue is that the library uses Serial1, but XOD is complaining it is not defined:

```auto
C:\Users\gweimer\AppData\Local\Temp\xod_temp_sketchbookztURTw\libraries\lx16a_servo/LX16AServo.h:4:17: error: 'Serial1' was not declared in this scope
         : _port(Serial1)

```

I see that it is defined here:

> xod/ **packages** /packages/arduino/hardware/avr/1.6.21/cores/arduino/HardwareSerial.h: extern HardwareSerial Serial1;

but adding #include \<HardwareSerial.h\> to my wrapper doesn’t help.

Here is what I have so far: [lx16a-servo.xodball](https://forum.xod.io/uploads/short-url/4JiinRg1xRryNFuEY0y38TVZyiC.xodball) (8.7 KB) lx16a-example is how I see it being used.

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [January 7, 2020, 5:09pm UTC](https://forum.xod.io/t/help-wrapping-arduino-libraries/3217/2 "2020-01-07T17:09:15Z")

</div>

I still haven’t found the reason for the folder, but if there is something that shouldn’t be

the declaration is in the three nodes of the example, usually the call is in a single node “device”

Another thing you notice is the use of  
`bus.begin()` … for this type of design

`bus->begin()` is used

ps: I think that being hardwareserial should be a different implementation, type library Visi Genie,

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [January 7, 2020, 6:44pm UTC](https://forum.xod.io/t/help-wrapping-arduino-libraries/3217/3 "2020-01-07T18:44:42Z")

</div>

try its

> **[franc0r/lx16a\_servo](https://github.com/franc0r/lx16a_servo)**
>
> C++ API for controlling Lewansoul LX-16A Servo (not rdy, not tested) - franc0r/lx16a\_servo

> **[osresearch/sneekbot](https://github.com/osresearch/sneekbot/tree/master/sneek)**
>
> Snake robot built with the LX16A servos. Contribute to osresearch/sneekbot development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [January 9, 2020, 4:07am UTC](https://forum.xod.io/t/help-wrapping-arduino-libraries/3217/4 "2020-01-09T04:07:09Z")

</div>

Rewrote to use sneekbot, and still having same problems. Header file needs copied to parent folder under ` __ardulib__ ` and Serial1 is still not defined:

> C:\Users\gweimer\AppData\Local\Temp\xod\_temp\_sketchbookoFxJkS\libraries\sneekbot\ServoLX.cpp: In member function ‘void ServoLX::begin()’:  
> C:\Users\gweimer\AppData\Local\Temp\xod\_temp\_sketchbookoFxJkS\libraries\sneekbot\ServoLX.cpp:40:2: error: ‘Serial1’ was not declared in this scope  
> Serial1.begin(115200);  
> ^

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [January 9, 2020, 4:46am UTC](https://forum.xod.io/t/help-wrapping-arduino-libraries/3217/5 "2020-01-09T04:46:31Z")

</div>

What micro are you compiling for? that error may not appear in a Mega

even if you don’t have a UNO, you can place Mega and compile, the compilation should have no error …just load error  
check the implementation of “Init” for vision genie, it is complex but use nodo “Uart” de xod

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [January 9, 2020, 4:54am UTC](https://forum.xod.io/t/help-wrapping-arduino-libraries/3217/6 "2020-01-09T04:54:30Z")

</div>

I have an UNO. Oddly, there is only option for UNO WiFi in XOD now…

It does compile if I select Mega…just can’t deploy to UNO then. Having trouble figuring out franc0r library you suggested, but it looks like it uses software serial & would be a better option for me…

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [January 9, 2020, 5:40am UTC](https://forum.xod.io/t/help-wrapping-arduino-libraries/3217/7 "2020-01-09T05:40:24Z")

</div>

I also had the problem, when two libraries are needed, I cannot and did not know how to define two types

then I used soft serial and I made the deficiencies (without using Type),  
in this case instead of using `"->"` is used `"."` and the development is very similar to what I would do in the arduino ide

ps: have you tried with Serial instead of Serial1?

* * *

LX16AServo.h

```auto
class LX16ABus {
public:
    LX16ABus()
        : _port(Serial)   
        , _baud(115200)
    {}

```

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [January 9, 2020, 1:54pm UTC](https://forum.xod.io/t/help-wrapping-arduino-libraries/3217/8 "2020-01-09T13:54:40Z")

</div>

I’m going to try programming it myself using soft-uart instead of using a library. Looks like most of the existing libraries are using hardware UART and are hard-coded for Serial1.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [January 10, 2020, 3:03am UTC](https://forum.xod.io/t/help-wrapping-arduino-libraries/3217/9 "2020-01-10T03:03:31Z")

</div>

Bah…XOD doesn’t like franc0r library’s includes:

```auto
#include <iostream>
#include <vector>
#include <cstdint>
#include <optional>

```

I guess I’ll have to code this without any building on existing libraries unless someone can help me get one of these libraries working. The other libraries for lx16a servos either are not C++, or they are hard-coded for Serial1, which Arduino UNO apparently doesn’t support.

Next question…will XString handle binary data, or will I need to add my own data type for passing messages that will be sent to servo?

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [January 10, 2020, 3:18pm UTC](https://forum.xod.io/t/help-wrapping-arduino-libraries/3217/10 "2020-01-10T15:18:04Z")

</div>

Maybe there is already a reference that I’m not seeing…[https://xod.io/docs/guide/custom-types/](https://xod.io/docs/guide/custom-types/) stops way short of what I need.

I THINK what I want to do is create my own lx16a class just so I can define some inline code utilities (like calculating checksum) and create my own datatype for accessing this class. Everywhere I use this class, I also need to access UART, so I would like to pass in a UART to my lx16a-servo-device, add class to define public inline functions, then create a struct that stores both the class & UART so I can pass both as SERVO to my send & receive nodes.

Is this even close?

```auto
class Lx16a{
public:
  inline static uint8_t checksum(const <uint8_t>& data)
  {
     <dummy code>
  }
}

struct State {
    uint8_t cmd[sizeof(Lx16a)];
    SoftwareUart* uart; 
};
void evaluate(Context ctx) {
    auto state = getState(ctx);
    state->uart = getValue<input_UART>(ctx);
    new (state->servo) Lx16a();
    emitValue<output_SERVO>(ctx, state);

```

How do we emit complex data? Can I emit state like above? When I use it in another node, can I access servo-\>uart and servo-\>cmd-\>checksum()?

Instead of passing my state data, do I need add UART to my new lx16a class?

Once I create the new joined data-type, how do I reference the parts?

Is there any existing documentation on creating/using joined data like this? Is there a good example I could be looking at?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/eb7348baa04192c2ef932d1db54d44f09f8a7888.png) [@system](https://forum.xod.io/u/system)\
**Post date:** [April 27, 2020, 6:59am UTC](https://forum.xod.io/t/help-wrapping-arduino-libraries/3217/11 "2020-04-27T06:59:45Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
