Sketch doesn't work on Teensy but works on Arduino

Status
Not open for further replies.

SteveO

Member
Hello,

I have my first Teensy on the way and want to get a USB MIDI project working on it. The project works just fine on an Arduino Uno r3 with a USB host shield. In anticipation of my Teensy 3.6 arriving I tried to verify/compile my sketch for Teensy and got an error message, again this sketch works on an Arduino Uno.

It seems the problem lies within the library I’m using, and I know nothing about troubleshooting libraries. What does this mean and where should I go for help? Is there a simple fix that I can make to to the MS3.h file? Finally, which USB types should I select under the Arduino IDE board options section? (I’ll am using a mini USB Host shield on the Uno and plan to do the same with the Teensy, unless there’s a better option.)

Thank you in advance.

Library I need to use: https://github.com/MrHaroldA/MS3

Here is a minimal sketch with enough sample code to illustrate the error:

Code:
/**
   This is an example for the MS-3 library.
Description removed…
*/

// Uncomment this to enable verbose debug messages.
//#define MS3_DEBUG_MODE

#include "Arduino.h"
#include "MS3.h"

// Initialize the MS3 class.
//MS3 MS3;

void setup() {
  // set up MS 3
  // I have code that goes here but isn't necessary to produce the error.
}

void loop() {
  // I have code that goes here but isn't necessary to produce the error.
}


Here is the error I get when verify/compiling the sketch:

Code:
Arduino: 1.8.8 (Mac OS X), TD: 1.45, Board: "Teensy 3.6, All of the Above, 16 MHz (No USB), Debug, US English"

In file included from /Users/steve/Documents/Arduino/deleteMe/deleteMe.ino:12:0:
/Users/steve/Documents/Arduino/libraries/MS3-master/MS3.h: In member function 'bool MS3::receive(long unsigned int&, byte&)':
/Users/steve/Documents/Arduino/libraries/MS3-master/MS3.h:184:46: error: no matching function for call to 'MS3::RecvData(unsigned int*, byte [64])'
             if (MS3::RecvData(&rcvd, incoming) == 0) {
                                              ^
In file included from /Users/steve/Documents/Arduino/libraries/MS3-master/MS3.h:75:0,
                 from /Users/steve/Documents/Arduino/deleteMe/deleteMe.ino:12:
/Users/steve/Documents/Arduino/libraries/USB_Host_Shield_2.0-master/usbh_midi.h:75:17: note: candidate: uint8_t USBH_MIDI::RecvData(uint16_t*, uint8_t*)
         uint8_t RecvData(uint16_t *bytes_rcvd, uint8_t *dataptr);
                 ^
/Users/steve/Documents/Arduino/libraries/USB_Host_Shield_2.0-master/usbh_midi.h:75:17: note:   no known conversion for argument 1 from 'unsigned int*' to 'uint16_t* {aka short unsigned int*}'
/Users/steve/Documents/Arduino/libraries/USB_Host_Shield_2.0-master/usbh_midi.h:76:17: note: candidate: uint8_t USBH_MIDI::RecvData(uint8_t*, bool)
         uint8_t RecvData(uint8_t *outBuf, bool isRaw=false);
                 ^
/Users/steve/Documents/Arduino/libraries/USB_Host_Shield_2.0-master/usbh_midi.h:76:17: note:   no known conversion for argument 1 from 'unsigned int*' to 'uint8_t* {aka unsigned char*}'
Error compiling for board Teensy 3.6.
 
Last edited:
Never mind, I got my sketch to compile by changing a line in the MS3.h file.

The MS3.h file read:
Code:
 unsigned int rcvd;;

            if (MS3::RecvData(&rcvd, incoming) == 0) {
                if (rcvd == 0) {
                    return false;
                }

I changed unsigned int rcvd; to read uint16_t rcvd;
 
Last edited:
That is one of the problems you run into when using Arduino code on a T3.6. The T3.6 is a 32-bit processor and therefore "int" is 32-bits instead of 16. As you've figured out, changing "int" to "uint16_t" will get rid of quite a few problems.
However, the fact that the code now compiles won't be much use to you on a T3.6.
Your main problem is that you are trying to compile an Arduino library for a Teensy 3.6 processor. The USB host hardware and software on the T3.6 is completely different from that of an Arduino.
First, you should set up a new directory for your teensy code/sketches. You have the directory /Users/steve/Documents/Arduino for Arduino code, now you need to create /Users/steve/Documents/Teensy for Teensy code. Under this will be /Users/steve/Documents/Teensy/libraries where you will install Teensy-specific libraries. I have two icons on my Windows desktop. One starts up the Arduino IDE in the Documents/Arduino directory and the other starts it up in the Documents/Teensy directory.
Once I had installed the MS3 library in my Teensy directory, I get a different error when compiling your code:
Code:
fatal error: usbh_midi.h: No such file or directory
This is because the Teensy does not use that usb host file at all. Your test didn't catch this because you compiled for Teensy from within your Arduino directory and the IDE therefore picked up any .h files that were in the Arduino library. This is why I suggest that you set up a separate Teensy directory.
When you compile usb host code for Teensy, you include USBHost_t36.h instead of usbh_midi.h. Then you'll have to modify MS3.h so that it works with the Teensy usb host midi. I don't think it'll be hard to do, but then I haven't tried it yet :)
What do you use the Arduino for when connected to the MS3? I'm not familiar with that device at all. Can you post an example of your Arduino code which shows the sort of functions that the Arduino performs?

Pete
 
Wow, thank you. I feel rather foolish now for not thinking about the architecture difference and also using a separate directory. I'm new to this stuff. I could have stuck with an Arduino but thought it would be fun to learn about Teensy. I know I've gone overboard with a 3.6 and I could have used an older model.

Basically, I want to send SysEx messages to a non-class compliant usb midi device (a Boss Katana amplifier). The SysEx messages also include a checksum value. Those are the things the MS3 library helps with. I was planning on using a Mini USB Host shield like this one: https://www.circuitsathome.com/usb-host-shield-hardware-manual/ along with the host shield library: https://github.com/felis/USB_Host_Shield_2.0.

I just posted a shortened version of my code and further explanation of what I am trying to do to: https://github.com/SteveObert/Katana_MS3. If you look at it you'll realize that I'm not a very experienced programmer. I know that and this is a work in progress, I'm sure there are better and more efficient ways to code what I'm trying to do.
 
Last edited:
Status
Not open for further replies.
Back
Top