A library to drive old AF Motor Shield

Hello!

@warner asked how he could control motors through Adafruit-alike Motor Shield in XOD and here is a small library. The shield is tricky one, its H-Bridges are placed behind a shift register chip. I couldn’t express it purely in XOD as it lacks some features yet, so I implemented the node from scratch in C++.

Here’s a quick demo:

3 Likes

Thanks for posting this! The library works great and is really easy to use!

Hi @nkrkv

Sorry for bumping such an old thread.

I’m getting errors when trying to upload to arduino UNO.

The errors in the compiler are as per the following excerpt (all constexpr for the pinout return the same error)

C:\Users\ryano\AppData\Local\Temp\xod_temp_sketchbookT9LnGw\xod_1623928764513_sketch\xod_1623928764513_sketch.ino:1080:35: error: non-static data member ‘DIR_LATCH’ declared ‘constexpr’
constexpr uint8_t DIR_LATCH = 12;
^~
C:\Users\ryano\AppData\Local\Temp\xod_temp_sketchbookT9LnGw\xod_1623928764513_sketch\xod_1623928764513_sketch.ino:1081:33: error: non-static data member ‘DIR_SER’ declared ‘constexpr’
constexpr uint8_t DIR_SER = 8;
^

I’m no good with code so I’m not sure what any of this means. Any help from you (or anyone else) is greatly appreciated.

This hack should get you up and running.

Open the dc-motors patch and then double-click on the not-implemented-in-xod node so that you can edit the C++ code.
Screenshot 2021-06-17 at 21.42.57

Screenshot 2021-06-17 at 22.03.32

Replace constexpr with const.

Screenshot 2021-06-17 at 21.42.17

1 Like

Thanks for the response!

I have no idea what I’m doing, but I ended up just deleting the ‘constexpr’ part completely and it seemed to work fine.

Is there any difference to having nothing before the integer VS having ‘const’ before?

Sorry again for the cluelessness…

const is used to define a constant, i.e. make the variable read-only. As you’ve seen, it’s not essential for the program to work, but it is good practice to declare variables that shouldn’t change as constant.

Constants can also be defined using constexpr. The initialization of a const variable can be deferred until run time, whereas a constexpr variable must be initialized at compile time. When a variable is initialized at compile time instead of run time, the program may run faster and use less SRAM.

2 Likes