Search results

  1. P

    USB Host not receiving messages (error allocating data transfer)

    usbMIDI refers to the USB _device_ interface of the Teensy (the one that's connected to your computer through the micro USB connector), not USB Host. You should create a MIDIDevice instance that represents a MIDI device connected to the host port. It will provide the necessary transfers, and...
  2. P

    MIDI Thru

    Here's what I use: Control Surface: MIDI-Monitor.ino
  3. P

    Where is the documentation for math functions?

    Arduino/Teensy code is compiled using a GCC C++ compiler, so you can just consult the C++ documentation: https://en.cppreference.com/w/cpp/header/cmath#Functions
  4. P

    Allocating memory with 'new', new(std::nothrow), testing -fcheck-new

    Indeed, if you need to handle out-of-memory conditions on a microcontroller with exceptions disabled, use new(std::nothrow). I think that's a good idea. Returning null is not allowed and does indeed seem to cause problems as shown above, so maybe calling __throw_bad_alloc() (or abort) is the...
  5. P

    Allocating memory with 'new', new(std::nothrow), testing -fcheck-new

    It's just the optimizer doing its job. The standard requires that `new` always returns a non-null pointer, so the optimizer can just throw away the entire `else` branch. See it for yourself on https://godbolt.org/z/aKoYqPKjr: #include <cstdint> void still_alive(); void out_of_memory(); void...
  6. P

    Arduino coding question --

    Some general comments: Don't use goto, use human-readable control structures like if, while, do-while, for, function calls, etc. instead: do { currentState = digitalRead(BUTTON_PIN); if(lastState == HIGH && currentState == LOW) Serial.println(); else if(lastState == LOW &&...
  7. P

    Exponential Moving Average - How does it work?

    But that doesn't solve the issue, you can shift it to the left as much as you like, in the end you have to represent everything in a finite number of bits, and no amount of filtering or shifting is going to prevent the last bit (or any bit really, through carrying) from flickering back and forth...
  8. P

    Exponential Moving Average - How does it work?

    I think this is an inherent problem with quantization, not necessarily because of the implementation of the filter (although different rounding/quantization methods might reveal it more easily than others, given that the filter inputs are quantized as well). Consider an ADC that measures a...
  9. P

    Could I streamline this code for LED control on Midi controller

    This might be useful: https://github.com/tttapa/Control-Surface/issues/241#issuecomment-660960589 It does roughly the same as the code you're using now (except the 3-way and 4-way switches), but with significantly simpler and shorter code. To improve your current code, move the updating of the...
  10. P

    Control Surface with Teensy for Beginners

    There is a wrapper, but you don't need it, Control Surface supports MIDI over hardware serial out of the box. For example: HardwareSerialMIDI_Interface serialmidi = Serial1; This line replaces the line “USBMIDI_Interface usbmidi;” that you'll find in most examples. The library has some classes...
  11. P

    MIDI causes crash on Teensy 4.1

    I don't think you're supposed to make copies of the serial ports. Not sure why the HardwareSerial copy constructor isn't deleted. If you want to declare the serial ports separately, use references instead: HardwareSerial &serialPort0 = Serial1; Pieter
  12. P

    Control Surface with Teensy for Beginners

    You might be interested in the Control Surface library for Arduino and Teensy that I maintain. It comes with many building blocks for creating MIDI controllers and control surfaces and has support for the Mackie Control Universal protocol (MCU). Control surfaces usually use the MIDI protocol...
  13. P

    Teensy3.6 UsbHost MIDI Performance Issues

    Changing the Interrupt Threshold Control value seems to alter the timing and might expose some data races. Occasionally, packets seem to be dropped when sending very long SysEx messages using my driver. I added some print statements to make sure it wasn't my code that was dropping them, and I...
  14. P

    Teensy3.6 UsbHost MIDI Performance Issues

    What exactly is the problem with the USBDriverTimer class? Is there anything you could use help with?
  15. P

    Teensy3.6 UsbHost MIDI Performance Issues

    You would inherit from the MIDI_Callback class and implement its onChannelMessage method. Then attach the callback to the MIDI interface using setCallbacks. For example: #include <Control_Surface.h> #include <MIDI_Interfaces/USBHostMIDI_Interface.hpp> USBHost myusb; USBHub hub1(myusb); USBHub...
  16. P

    Teensy3.6 UsbHost MIDI Performance Issues

    Sure, the code for the T4.0 simply discards any incoming MIDI USB data (compiled with USB type “MIDI”, of course): void setup() { pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); delay(100); digitalWrite(LED_BUILTIN, LOW); } void loop() { (void)usb_midi_read_message(); }...
  17. P

    Teensy3.6 UsbHost MIDI Performance Issues

    I've been working on a more efficient implementation of the USB host MIDI driver. It uses alternating transmit buffers and disables interrupts only for a minimal amount of time, which allows for high throughput. It also implements a timeout that's started whenever an empty transmit buffer is...
  18. P

    Raspberry Pi Pico

    On a related note: Raspberry Pi also boasts about the SWD debugging support on the Pico. A $4 SWD debugger sounds pretty nice. I've tried their “Picoprobe” firmware and their fork of OpenOCD to connect to my Arduino Nano 33 BLE. It detects the Pico correctly, but it seems to crash when...
  19. P

    Raspberry Pi Pico

    Maybe it was because I already had some of the necessary dependencies and tools installed, but for me it was as simple as installing the PlatformIO extension in VSCode and clicking the “new project” button. After selecting the board I wanted to use, it automatically downloaded the necessary...
  20. P

    Raspberry Pi Pico

    IIRC, the Arduino Pro IDE is based on Eclipse Theia, which is an open-source VSCode alternative. The problem with VSCode is that it's not really open-source. It's built on open-source and large parts of the source code are available, but the binaries distributed by Microsoft are not open-source...
  21. P

    Analog read affected by multiple pots using the Audio Shield

    The Teensy 4.0 is a 3.3V device, connecting analog pins to 5V will destroy it. Your potentiometers should be wired to 3.3V, not 5V. Pieter
  22. P

    Interval Timer, Function Pointers, and Variables.

    You could use a lambda function: OLEDIntervalTimer.begin(+[]{ enableCyclePointer(&currentGlobals); }, 6); Pieter
  23. P

    Serial monitor can't read from Teensy 3.6 on Ubuntu 20.04 but can on Windows10

    I've been using Teensy on Ubuntu 20.04 since it came out in April (and on 19.10, 18.04 and 16.04 before that), and I've never had any problems with the serial monitor. When selecting the 'Serial' USB mode, the Teensy shows up at /dev/ttyACM0 (or a higher number if you have multiple devices...
  24. P

    midi in with 3.5mm connector overvoltage protection cuircuit

    MIDI uses a current loop, not voltage. It's normal that you don't measure any voltage at the output of your circuit, it only needs to source current. By adding some kind of pull-up network (e.g. by connecting it to a MIDI in port), you should see a voltage after the diode. 3.3V is quite low...
  25. P

    teensy midi

    I posted a working example for a MIDI controller with buttons and an encoder. Did it not work for you? If you want to write your own code from scratch, you'll have to learn some basics about the Arduino/Teensyduino environment and the C++ programming language. Just copy-and-pasting code that...
  26. P

    teensy midi

    The MCU::PLAY constant is for the Mackie Control Universal protocol specifically. If you don't use that protocol, the controller numbers don't really have any meaning apart for the MIDI mapping you create in your DAW. 28::PLAY is not valid C++ syntax, if you want to specify the controller...
  27. P

    teensy midi

    You have to write code, there's no way around that. You have to tell the Teensy what MIDI messages to send and when, and how it should react to the incoming MIDI messages it receives. I'm the maintainer of the Control Surface library, which allows you to design a MIDI controller in a...
  28. P

    Teensy 4.1 crash, using ILI9341 and ArduinoJson

    There are very few circumstances where you should be using “new” in modern C++. The code you linked to uses “new” and owning raw pointers, and leaks memory as a result. For example here: std::vector<SequenceInstrumentTrackProgram *> instrumentTrackPrograms; auto *instrumentTrackProgram = new...
  29. P

    Teensy 4.0 crash with BigNumber variables

    A quick glance at the source seems to reveal that the default constructor copies the contents of a pre-allocated “zero” constant BigNumber. This constant is created when calling BigNumber::begin(), so if you don't initialize it first, “zero” is still null, and it crashes. I agree that it's poor...
  30. P

    Teensy 4.0 crash with BigNumber variables

    Something like this, perhaps? class Foo { public: static BigNumber* getBarPtr() { static BigNumber bar; // Costructed when this function is first called return &bar; } }; Of course, you should only call this function after initializing the library, which might just move...
  31. P

    Teensy 4.0 crash with BigNumber variables

    You cannot create a BigNumber before calling BigNumber::begin(), otherwise the BigNumber constructor will dereference a null pointer and crash your program. Pieter
  32. P

    Is it possible to rename the individual ports in MIDIx4 or MIDIx16 mode?

    You can use the “usb_string_midi_port1” through “usb_string_midi_port16” constants. By default, the names used are “Port *”, see usb_desc.c#L1686. You can define these names as shown here, for example: #include "usb_names.h" struct usb_string_descriptor_struct usb_string_midi_port1 = {...
  33. P

    Is there any filter libraries for teensies out there?

    I don't have too much time to look into it right now, but here are a couple of things you could try: - Try using doubles instead of floats. If it's a numerical issue, there should be a difference. - Try implementing the filter as filtered = prev + alpha * (input - prev) - Try using integers...
  34. P

    Is there any filter libraries for teensies out there?

    I'm not familiar with “denormalisation” in digital filters. In analog filter design, there seems to be a technique called denormalisation, but I'm not familiar with it. In all floating point operations, you can end up with really small numbers that cannot be represented in the standard...
  35. P

    Is there any filter libraries for teensies out there?

    I maintain this Arduino-Filters library. It supports Butterworth filters out of the box, as you can see in this example: Butterworth.ino Ideally, this example is all you need to filter some sensor data. If you want to delve into it a little deeper, you can find the derivation of the...
  36. P

    initial Ableton cc massage state

    I don't use Ableton myself, but in my experience, DAWs will usually send all relevant MIDI data when you start the application, when you open a new project, or when you configure the control surface. If you can connect the Teensy before starting the DAW, that should work in most cases. There are...
  37. P

    I2C interrupts on a MCP23017

    Basically it just reads the states of all the pins, and for each pair of pins, it compares them to the previous states. This is done by combining the two new states and the two old states as a 4-bit number: "new state B | new state A | old state B | old state A". There are only 16 possibilities...
  38. P

    I2C interrupts on a MCP23017

    Here's what I use: https://github.com/tttapa/Arduino-Helpers/blob/master/src/AH/Hardware/MCP23017Encoders.hpp See this example: https://tttapa.github.io/Arduino-Helpers/Doxygen/d0/db3/MCP23017-Encoders-Interrupts_8ino-example.html
  39. P

    I2C interrupts on a MCP23017

    I see you've edited your reply, glad you got it working. If you have multiple chips, you could tie all of their interrupt pins together (use open-drain output on the MCPs and input pull-up enabled on the Teensy). When an interrupt fires, you don't know which MPC triggered it, so you have to...
  40. P

    I2C interrupts on a MCP23017

    When a pin of the MCP changes state, the interrupt output goes low. This should trigger an interrupt on the Teensy. In the ISR, you read the MCP input register, and this read request causes the MPC to make the interrupt output high again. If you don't read the register, the interrupt pin will...
  41. P

    I2C interrupts on a MCP23017

    The MCP will keep the interrupt pin low until you read the input register of the port that caused the interrupt, so you have to read the data in your ISR. This also implies that the correct interrupt mode is LOW, not FALLING. Pieter
  42. P

    MIDI Message Queue

    A latency of 27ms doesn't seem right at all. I'm not familiar with the Adafruit libraries you mention, but I did write a MIDI BLE library for ESP32. The way I handle it there is by buffering the Bluetooth packets, rather than the MIDI messages, I think this should simplify the rest of the code...
  43. P

    MIDI Message Queue

    What exactly do you need a queue for? Usually, you want to keep the latency as low as possible, so you'd avoid queuing up any MIDI data. The serial port or USB MIDI code you're using already has its own queue, for both sending and receiving data. Do you intend to use these queues inside of...
  44. P

    Exponential Moving Average - How does it work?

    For my purposes, and as a beginner-friendly Arduino/Teensy sketch, using the same size for the state as for the input is a perfectly sensible default. You can still supply your own types as a template parameter if you don't want to use the default. You could even change the default if you feel...
  45. P

    Exponential Moving Average - How does it work?

    Agreed, I added a check and more comments on the page: https://tttapa.github.io/Pages/Mathematics/Systems-and-Control-Theory/Digital-filters/Exponential%20Moving%20Average/C++Implementation.html#improved-c-implementation You can now verify the range: EMA<5, int_fast16_t> filter...
  46. P

    Exponential Moving Average - How does it work?

    For truly random inputs, it probably doesn't matter, but the problem with truncation is that it makes it impossible to reach zero again (assuming non-negative inputs). Using a rectangular input from 0 to 16 and back to 0, for instance: Nice, that's indeed a better solution than the...
  47. P

    Exponential Moving Average - How does it work?

    Ah, I see what you mean. The difference is of course that both 'Decay' and 'Exponential' use floating point states and operations, whereas the C++ implementation uses only integer arithmetic, so it's not a surprise that the output differs some of the time. The reason for the integer...
  48. P

    Exponential Moving Average - How does it work?

    Indeed, @xenington where did you get that code from? The pages you linked to seem to list the correct code (https://tttapa.github.io/Pages/Mathematics/Systems-and-Control-Theory/Digital-filters/Exponential%20Moving%20Average/C++Implementation.html#implementation-in-c). Where does the second...
  49. P

    .ARM.exidx section question

    You're right, I didn't double-check my version, I meant 1.52, 1.53 does indeed seem to include the change.
Back
Top