Go Down

Topic: Arduino Due libraries (official and 3rd party) (Read 288945 times) previous topic - next topic

ZackT86

Im using get.modifiers with a keyboard and everytime I press a key the output is 0 and not the proper value. Im new please help!!

Santechbox

I need arduino due library for connecting multiple TCA9548A 8 channel I2C expander.  Does anyone have connected three TCA9548A in a single I2C line of Arduino due?  Please help with this.

MartinZ

#152
Mar 31, 2019, 06:10 pm Last Edit: Mar 31, 2019, 10:30 pm by MartinZ Reason: new information after done some research.
Hi ,

finally i got my "Yamaha THR10" (guitar amp, that can be configured via MIDI-SysEx) working with USBHost Library (arduino-libraries/USBHost)
in conjunction with the
" bbx10/USBH-Midi branch Due"-library

on "Arduino Due", but there were several problems to solve before:


Concerning library (arduino-libraries/USBHost):

USB-Enumeration works only, if Debug-outputs are enabled in USBHost.h

Code: [Select]

#define TRACE_USBHOST(x) x
//#define TRACE_USBHOST(x)


otherwise device is not detected.

Don't ask me why…
Is it perhaps a timing problem, that is solved when a "printf" delays process at the right time?
 (Edit: in fact there are two places in USB.cpp, where short delays are necessary to get it work.
          You can leave TRACE_USBHOST(x) x   like it was, if you add that two delays.
          Details at the end of this message!)

Has anyone had the same Problem with (native) USBHost - Library for  Due?


Issues concerning library (bbx10/USBH-Midi branch Due):

Adding an "else if" in descriptor parsing

Code: [Select]

if( buf_ptr[5] == USB_CLASS_AUDIO && buf_ptr[6] == USB_SUBCLASS_MIDISTREAMING )
{ //p[5]; bInterfaceClass = 1(Audio), p[6]; bInterfaceSubClass = 3(MIDI Streaming)
isMidiFound = true; //MIDI device found.
isMidi = true;
}
//Yamaha THR10
else if( buf_ptr[5] == USB_CLASS_VENDOR_SPECIFIC && buf_ptr[6] == USB_SUBCLASS_MIDISTREAMING ) //Yamaha THR10
{
//p[5]; bInterfaceClass = 255(VENDOR), p[6]; bInterfaceSubClass = 3(MIDI Streaming)
isMidiFound = true; //MIDI device found.
isMidi = true;
}
else
{
#ifdef DEBUG
Serial.print("No MIDI Device\n");
#endif
// buf_ptr += total_length + 1;
// bConfNum = 0;
isMidi = false;
}
break;


Solving buffer problems:

always use (uint16_t) cast instead of (uint8_t) cast for epInfo[index].maxPktSize
e.g.

Code: [Select]

// Extract Max Packet Size from device descriptor
epInfo[0].maxPktSize = (uint16_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0;
quick and dirty change for buffersize, that works for THR10 (just a work around, no proper solution, i guess!!!):
if( isMidi )
{
if ((epDesc->bEndpointAddress & 0x80) == 0x80)
{
// Input
index = epDataInIndex;
epInfo[index].epAddr = (epDesc->bEndpointAddress & 0x0F);
//epInfo[index].maxPktSize = (uint16_t)epDesc->wMaxPacketSize;
epInfo[index].maxPktSize = (uint16_t)2048; //necessary for YAMAHA THR10
pipe = UHD_Pipe_Alloc(bAddress, epInfo[index].epAddr, UOTGHS_HSTPIPCFG_PTYPE_BLK, UOTGHS_HSTPIPCFG_PTOKEN_IN, epInfo[index].maxPktSize, 0, UOTGHS_HSTPIPCFG_PBK_1_BANK);
}
else
{
// Output
index = epDataOutIndex;
epInfo[index].epAddr = (epDesc->bEndpointAddress & 0x0F);
//epInfo[index].maxPktSize = (uint8_t)epDesc->wMaxPacketSize;
epInfo[index].maxPktSize = (uint16_t)2048; //necessary for YAMAHA THR10
pipe = UHD_Pipe_Alloc(bAddress, epInfo[index].epAddr, UOTGHS_HSTPIPCFG_PTYPE_BLK, UOTGHS_HSTPIPCFG_PTOKEN_OUT, epInfo[index].maxPktSize, 0, UOTGHS_HSTPIPCFG_PBK_1_BANK);
}



After that modifikations, i can send System-Exlusive Messages to THR10, like
Code: [Select]

uint8_t msg1[]= {0xF0,0x43,0x7D,0x30,0x41,0x30,0x01,0x01,0xF7}; //Lamp off
uint8_t msg2[]= {0xF0,0x43,0x7D,0x30,0x41,0x30,0x01,0x00,0xF7}; //Lamp on


that switches the light of the Guitar-Amp (just a test,  more important, I can send sound-patches, that are created as a file before with the THR10-Editor on PC.)

This way I can build a foot-switch / pedal to change sound patches on the fly like
in the THR10 foot switch project of

http://www.mehlbrandt.de/thr/thr_1

But this guy did it with an ordinary Arduino Uno and anUSB-Host Shield.


With the Due I can use the native USB-Host-Port, have got more memory and speed.
I want to inject Samples to the THR10 with this footswitch as well, as it can also act as IN-/OUT Audio Interface.

EDIT:
1.) Add a delayMicroseconds(300ul); in  function  "USBHost::ctrlReq"   where the following lines occure:

Code: [Select]

if (dataptr != 0)
{
if (direction)
{
// IN transfer
TRACE_USBHOST(printf("    => ctrlData IN\r\n");)

Add here---->              delayMicroseconds(300ul);  //necessary!! 275ul does not work!!


2) Add a delayMicroseconds(120ul);  at start of  function  "USBHost::dispatchPkt"

Code: [Select]

uint32_t USBHost::dispatchPkt(uint32_t token, uint32_t hostPipeNum, uint32_t nak_limit)
{
uint32_t timeout = millis() + USB_XFER_TIMEOUT;
uint32_t nak_count = 0;
uint32_t rcode = USB_ERROR_TRANSFER_TIMEOUT;

---> add here: delayMicroseconds(120ul);  //NECESSARY!!  (100ul does not work!)

TRACE_USBHOST(printf("     => dispatchPkt token=%lu pipe=%lu nak_limit=%lu\r\n", token, hostPipeNum, nak_limit);)


Don't really know  w h y   this have to be done. But it does nor work otherwise.

 ;)

MartinZ

#153
May 10, 2019, 12:48 am Last Edit: Jun 04, 2019, 07:33 am by MartinZ Reason: Link for Library
Just published a fast ILI9225 library for Arduino Due.

https://github.com/martinzw/ILI9225_Due

It uses DMA and works much faster than the well known  TFT_22_ILI9225 library.


It is an adaption/mixture of ILI9341_Due and ILI9225_t3.

Carlos_Correa09

Hello
Your help please.
I have an ARDUINO DUE card and I am using the NexDualStateButton buttons to be able to program with an NEXTION screen NX8048K070_011C but the problem is that when compiling the following comes up:
'NexDSButton' does not name a type, even using the example that comes in the library (CompDualStateButton).

obihavemojo

Hi all,

This post is just to anounce that I have developed a library for the DUE which takes advantage of several features of the Timer Counter (TC) modules available in Atmel's ATSAM3X8E.

The name of the library is tc_lib and it is openly available at:

 https://github.com/antodom/tc_lib


In its initial operative version the library provides two kind of objects:

  • Capture objects. With these objects you can measure the period and pulse (duty) of a typical digital signal, like a PWM signal. In fact, the example provided measure the signal generated with analogWrite().
  • Action objects. These objects allow to associate a callback function to any of the TC channels (you have nine in total), such that the function its called with the period you establish. The resolution of the period is in microseconds.

You have available examples using both types of objects, I hope the examples are self-explaining.

More info about tc_lib in https://github.com/antodom/tc_lib.

Drop me a line if you have any question or interest.

Hi. Thanks a lot for this interesting library. I am trying to use "action_tc0" mode to measure the time (in us) which a part of my code (a while loop which digitalread a pin) takes to run, something similar to what micro() function does (which uses TC0), but I am looking for a more precise implementation. What is the best way to do this? I have tried to use the counter inside the set_led_action, but it just always returns 2! whereas when using micros, it returns correct times (but with a resolution of around 2us, I want 1us)

nitrof

Quote
but it just always returns 2!
Please provide codeof what you have right now...


Regards.

Nitrof

obihavemojo

#157
Feb 13, 2020, 12:02 pm Last Edit: Feb 21, 2020, 10:07 am by obihavemojo
Hi, here is the code, some modification to original code, a sinusoidal signal is given to AD1 pin, which digitalRead used to read that, the aim is to measure the time that signal is high, using timer instead of the micro function.

antodom

Hi there @obihavemojo,

If you want a 1 usec period, CALLBACK_PERIOD should be 100, not 1000000. Take into account that tc_lib uses as time unit for the period hundreths of usecs. (1e-8 secs.)

Best.
------------
antodom

obihavemojo

Hi there @obihavemojo,

If you want a 1 usec period, CALLBACK_PERIOD should be 100, not 1000000. Take into account that tc_lib uses as time unit for the period hundreths of usecs. (1e-8 secs.)

Best.
Hi, thanks a lot, that actually works correctly, and jitter is nicely very low. That's for generating a pulse every 1us.

Still, from the code I had attached, I need to use this timer to measure the time it takes for the while loop that reads the digital pin which is fed by a constant frequency signal, for example, a 200 kHz square or sine wave, the counter value stays the same (no measurement of the past time) when I check the action_ctx.counter before and after the while loop; and it does not change when I change the frequency of the input, for example, double it, or halve it.
Maybe reading a digital pin mess up the timer interrupts, not sure.

Regards

antodom

Hi again @obihavemojo,

If what you want is to measure the frequency and due time (pulse width) of a digital signal, use tc_lib's capture objects. Have a loop to example capture_test.ino which comes with the library. I think you can adapt it easily for your purposes.

I hope it helps.
------------
antodom

obihavemojo

Hi again @obihavemojo,

If what you want is to measure the frequency and due time (pulse width) of a digital signal, use tc_lib's capture objects. Have a loop to example capture_test.ino which comes with the library. I think you can adapt it easily for your purposes.

I hope it helps.
Hi, thanks again, I want to do the measurements on a sine signals. Maybe converting sine to pulse is an option.
In general, for higher frequencies of timer there is some jitter. The strange thing is sometimes for a higher frequency there is lower jitter than a lower frequency. It is like in somehow the timer frequency needs to be a multiple of certain values to reach the best behavior (lowest jitter). Not sure to be honest



khoih-prog

EthernetWebServer

EthernetWebServer

To install using Library Manager

EthernetWebServer


From v1.0.3+, the library supports more Arduino boards ( SAM DUE, SAMD: ZERO, MKR, NANO_33_IOT, M0, M0 Pro, AdaFruit CIRCUITPLAYGROUND_EXPRESS, etc.)

From v1.0.2+, the library supports many more Arduino boards (Atmel AVR-s, Atmel SAM3X8E ARM Cortex-M3, STM32F series, ESP8266, Intel ARC32(Genuino101), Nordic nRF51(RFduino), Teensy boards, Realtek Ameba(RTL8195A,RTL8710))

Support Wiznet W5x00 or ENC28J60 Ethernet shields by using UIPEthernet library besides standard Ethernet library

This is simple yet complete WebServer library for AVR, Teensy,SAM, SAMD, ESP, STM32F, Intel, etc. boards running Ethernet shields. The functions are similar and compatible to ESP8266/ESP32 WebServer libraries to make life much easier to port sketches from ESP8266/ESP32.

The library supports
1. HTTP Server and Client
2. HTTP GET and POST requests, provides argument parsing, handles one client at a time.

Library is based on and modified from Ivan Grokhotkov's ESP8266WebServer)

The EthernetWebServer class found in EthernetWebServer.h header, is a simple web server that knows how to handle HTTP requests such as GET and POST and can only support one simultaneous client.

Sample Code

Code: [Select]

#if    ( defined(ARDUINO_SAM_DUE) || defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \
      || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \
      || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(__SAMD21G18A__) \
      || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAM3X8E__) || defined(__CPU_ARC__) )      
  #if defined(ESP8266_AT_USE_SAMD)
    #undef ESP8266_AT_USE_SAMD
  #endif
  #define ESP8266_AT_USE_SAMD      true
#endif

#if defined(ESP8266_AT_USE_SAMD)
// For SAMD
  #define EspSerial Serial1
  
  #if defined(ARDUINO_SAMD_ZERO)
    #define BOARD_TYPE      "SAMD Zero"
  #elif defined(ARDUINO_SAMD_MKR1000)
    #define BOARD_TYPE      "SAMD MKR1000"    
  #elif defined(ARDUINO_SAMD_MKRWIFI1010)
    #define BOARD_TYPE      "SAMD MKRWIFI1010"
  #elif defined(ARDUINO_SAMD_NANO_33_IOT)
    #define BOARD_TYPE      "SAMD NANO_33_IOT"  
  #elif defined(ARDUINO_SAMD_MKRFox1200)
    #define BOARD_TYPE      "SAMD MKRFox1200"
  #elif ( defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) )
    #define BOARD_TYPE      "SAMD MKRWAN13X0"
  #elif defined(ARDUINO_SAMD_MKRGSM1400)
    #define BOARD_TYPE      "SAMD MKRGSM1400"
  #elif defined(ARDUINO_SAMD_MKRNB1500)
    #define BOARD_TYPE      "SAMD MKRNB1500"
  #elif defined(ARDUINO_SAMD_MKRVIDOR4000)
    #define BOARD_TYPE      "SAMD MKRVIDOR4000"
  #elif defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
    #define BOARD_TYPE      "SAMD ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS"
  #elif ( defined(ARDUINO_SAM_DUE) || (__SAM3X8E__) )
    #define BOARD_TYPE      "SAM DUE"
  #elif ( defined(__SAMD21G18A__) || (__CPU_ARC__) )
    #define BOARD_TYPE      "SAMD Board"
  #else
    #define BOARD_TYPE      "SAMD Unknown"
  #endif
#elif ( defined(CORE_TEENSY) )
  // For Teensy 4.0
  #if defined(__IMXRT1062__)
  #define BOARD_TYPE      "TEENSY 4.0"
  #elif ( defined(__MKL26Z64__) || defined(ARDUINO_ARCH_AVR) )
  #define BOARD_TYPE      "TEENSY LC or 2.0"
  #else
  #define BOARD_TYPE      "TEENSY 3.X"
  #endif
#else
  // For Mega
  #define BOARD_TYPE      "AVR Mega"
#endif

#include <SPI.h>

// Use true  for ENC28J60 and UIPEthernet library (https://github.com/UIPEthernet/UIPEthernet)
// Use false for W5x00 and Ethernetx library      (https://www.arduino.cc/en/Reference/Ethernet)
//#define USE_UIP_ETHERNET   true

#include <EthernetWebServer.h>



// Enter a MAC address and IP address for your controller below.

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

// Select the IP address according to your local network
IPAddress ip(192, 168, 2, 200);

EthernetWebServer server(80);

const int led = 13;

void handleRoot()
{
  server.send(200, "text/plain", "Hello from EthernetWebServer");
}

void handleNotFound()
{
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++)
  {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  digitalWrite(led, 0);
}

void setup(void)
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  delay(1000);
  Serial.println("\nStarting HelloServer on " + String(BOARD_TYPE));

  // start the ethernet connection and the server:
  Ethernet.begin(mac, ip);

  server.on("/", handleRoot);

  server.on("/inline", [](){
    server.send(200, "text/plain", "This works as well");
  });

  server.onNotFound(handleNotFound);

  server.begin();

  Serial.print(F("HTTP EthernetWebServer is @ IP : "));
  Serial.println(Ethernet.localIP());
}

void loop(void)
{
  server.handleClient();
}



mtorruella

HI

I am using and arduino due with SIM900 Shield and i am having problem with GPRS_Shield_Arduino.h and SofwareSerial.h library, seem is not compatible with due, there are a solution for use SIM900 shield with due?

Thanks in advance

nitrof

@mtorruella provide code and what is your actual error.

Go Up