Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Audio bridge to Ethernet, is it possible?

  1. #1

    Audio bridge to Ethernet, is it possible?

    Hi all,

    Your options are welcome on this idea:
    Would it be possible to make a Audio to ethernet bridge on a teensy 4.1?

    Audio will be send from an external ADC using TDM, 100kHz, 24 bits, 4 or 8 channels. This audio needs to be processed on a Rasb Pi. I figured a Ethernet connection might be good for that task.

    Is it possible, or should I look for different route?


    Thanks for any comments you might have.
    Thijs Schrama

  2. #2
    Just Bumping.... I am about to start working on this task. Any warning, remarks, opinions are welcome.

  3. #3
    Today I started experimenting.

    This code compiles fine, but halts the ethernet configuration. Do any of you know why?


    Code:
    / MATLABUDPBroadcastExample.ino
    // Copyright 2016 The MathWorks, Inc.
    // some edits T Schrama july 2020 for teensy 4.1 nativeEthernet
    
    #include <SPI.h>
    #include <Ethernet.h>
    #include <EthernetUdp.h>
    
    int ledPin = LED_BUILTIN;                                    // Connect an LED->330Ohm to pin 5 or LED_BUILTIN
    
    int packetSize;
    
    //byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xAD, 0xDE};
    
    uint8_t mac[6];
    
    unsigned int broadcastPort = 31416;      
    char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  
    char  ArduinoAckMessage[] = "Arduino:ACK\r";       // "\r" is the carriage return, i.e., char(13)
    char MATLABBlinkItCommand[] = "MATLAB:BlinkIt\r";  
    EthernetUDP Udp;
    IPAddress broadcastAddress;
    
    void setup()
    {
      teensyMAC(mac);  // function to auire Teensy 4.1 NativeEthernet MAC,  function is define below
      Serial.begin(9600);
      if (Ethernet.begin(mac)==0){
        Serial.println("Failed to configure Ethernet. Halt.");
        delay(1000);                                  // Allow some time for message to be printed
        abort();
      }
      Serial.print("Arduino's IP Address is: ");
      Serial.println(Ethernet.localIP());
      Udp.begin(broadcastPort);  
      pinMode(ledPin, OUTPUT);      
      digitalWrite(ledPin, LOW);    
    }
    
    void loop()
    {
      // if there's data available, read a packet
      packetSize = Udp.parsePacket();
      if (packetSize) {
        Serial.print("Message: ");
        Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
        packetBuffer[packetSize] = '\0';
        Serial.println(packetBuffer);
        if (strcmp(packetBuffer, MATLABBlinkItCommand) == 0)
        {
          broadcastAddress = Udp.remoteIP();
          broadcastAddress[3] = 255;
          Udp.beginPacket(broadcastAddress, broadcastPort);
          Udp.write(ArduinoAckMessage);
          Udp.endPacket();
          digitalWrite(ledPin, HIGH);                   // sets the LED on
          delay(1000);                                  // waits for a second
          digitalWrite(ledPin, LOW);                    // sets the LED off
        }
      }
      delay(10);  
    }
    
    // code to aquire MAC adres of teensy 4.1 nativeEthernet
    void teensyMAC(uint8_t *mac) {
    
      static char teensyMac[23];
      
      #if defined(HW_OCOTP_MAC1) && defined(HW_OCOTP_MAC0)
        Serial.println("using HW_OCOTP_MAC* - see https://forum.pjrc.com/threads/57595-Serial-amp-MAC-Address-Teensy-4-0");
        for(uint8_t by=0; by<2; by++) mac[by]=(HW_OCOTP_MAC1 >> ((1-by)*8)) & 0xFF;
        for(uint8_t by=0; by<4; by++) mac[by+2]=(HW_OCOTP_MAC0 >> ((3-by)*8)) & 0xFF;
    
        #define MAC_OK
    
      #else
        
        mac[0] = 0x04;
        mac[1] = 0xE9;
        mac[2] = 0xE5;
    
        uint32_t SN=0;
        __disable_irq();
        
        #if defined(HAS_KINETIS_FLASH_FTFA) || defined(HAS_KINETIS_FLASH_FTFL)
          Serial.println("using FTFL_FSTAT_FTFA - vis teensyID.h - see https://github.com/sstaub/TeensyID/blob/master/TeensyID.h");
          
          FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
          FTFL_FCCOB0 = 0x41;
          FTFL_FCCOB1 = 15;
          FTFL_FSTAT = FTFL_FSTAT_CCIF;
          while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
          SN = *(uint32_t *)&FTFL_FCCOB7;
    
          #define MAC_OK
          
        #elif defined(HAS_KINETIS_FLASH_FTFE)
          Serial.println("using FTFL_FSTAT_FTFE - vis teensyID.h - see https://github.com/sstaub/TeensyID/blob/master/TeensyID.h");
          
          kinetis_hsrun_disable();
          FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
          *(uint32_t *)&FTFL_FCCOB3 = 0x41070000;
          FTFL_FSTAT = FTFL_FSTAT_CCIF;
          while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
          SN = *(uint32_t *)&FTFL_FCCOBB;
          kinetis_hsrun_enable();
    
          #define MAC_OK
          
        #endif
        
        __enable_irq();
    
        for(uint8_t by=0; by<3; by++) mac[by+3]=(SN >> ((2-by)*8)) & 0xFF;
    
      #endif
    
      #ifdef MAC_OK
        sprintf(teensyMac, "MAC: %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
        Serial.println(teensyMac);
      #else
        Serial.println("ERROR: could not get MAC");
      #endif
    }

  4. #4
    OK, got it working.

    First, I had to bridge my ethernet in my computer, so the teensy sees my DHCP from my home-internet-provider-modem(?)
    Second, I had to change the ethernet library to the nativeEthrnet library.

    Code:
    #include <fnet.h>
    #include <fnet_config.h>
    #include <fnet_user_config.h>
    
    #include <NativeEthernet.h>
    
    // MATLABUDPBroadcastExample.ino
    // Copyright 2016 The MathWorks, Inc.
    // some edits T Schrama july 2020 for teensy 4.1 nativeEthernet
    
    #include <SPI.h>
    //#include <Ethernet.h>
    //#include <EthernetUdp.h>
    
    int ledPin = LED_BUILTIN;                                    // Connect an LED->330Ohm to pin 5 or LED_BUILTIN
    
    int packetSize;
    
    //byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xAD, 0xDE};
    
    uint8_t mac[6];
    
    unsigned int broadcastPort = 31416;      
    char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  
    char  ArduinoAckMessage[] = "Arduino:ACK\r";       // "\r" is the carriage return, i.e., char(13)
    char MATLABBlinkItCommand[] = "MATLAB:BlinkIt\r";  
    EthernetUDP Udp;
    IPAddress broadcastAddress;
    
    void setup()
    {
      teensyMAC(mac);                                // function to auqire Teensy 4.1 NativeEthernet MAC,  function is defined below
      Serial.begin(9600);
      if (Ethernet.begin(mac)==0){
        Serial.println("Failed to configure Ethernet. Halt.");
        delay(1000);                                  // Allow some time for message to be printed
        abort();
      }
      Serial.print("Arduino's IP Address is: ");
      Serial.println(Ethernet.localIP());
      Udp.begin(broadcastPort);  
      pinMode(ledPin, OUTPUT);      
      digitalWrite(ledPin, LOW);    
    }
    
    void loop()
    {
      // if there's data available, read a packet
      packetSize = Udp.parsePacket();
      if (packetSize) {
        Serial.print("Message: ");
        Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
        packetBuffer[packetSize] = '\0';
        Serial.println(packetBuffer);
        if (strcmp(packetBuffer, MATLABBlinkItCommand) == 0)
        {
          broadcastAddress = Udp.remoteIP();
          broadcastAddress[3] = 255;
          Udp.beginPacket(broadcastAddress, broadcastPort);
          Udp.write(ArduinoAckMessage);
          Udp.endPacket();
          digitalWrite(ledPin, HIGH);                   // sets the LED on
          delay(1000);                                  // waits for a second
          digitalWrite(ledPin, LOW);                    // sets the LED off
        }
      }
      delay(10);  
    }
    
    // code to aquire MAC adres of teensy 4.1 nativeEthernet
    void teensyMAC(uint8_t *mac) {
    
      static char teensyMac[23];
      
      #if defined(HW_OCOTP_MAC1) && defined(HW_OCOTP_MAC0)
        Serial.println("using HW_OCOTP_MAC* - see https://forum.pjrc.com/threads/57595-Serial-amp-MAC-Address-Teensy-4-0");
        for(uint8_t by=0; by<2; by++) mac[by]=(HW_OCOTP_MAC1 >> ((1-by)*8)) & 0xFF;
        for(uint8_t by=0; by<4; by++) mac[by+2]=(HW_OCOTP_MAC0 >> ((3-by)*8)) & 0xFF;
    
        #define MAC_OK
    
      #else
        
        mac[0] = 0x04;
        mac[1] = 0xE9;
        mac[2] = 0xE5;
    
        uint32_t SN=0;
        __disable_irq();
        
        #if defined(HAS_KINETIS_FLASH_FTFA) || defined(HAS_KINETIS_FLASH_FTFL)
          Serial.println("using FTFL_FSTAT_FTFA - vis teensyID.h - see https://github.com/sstaub/TeensyID/blob/master/TeensyID.h");
          
          FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
          FTFL_FCCOB0 = 0x41;
          FTFL_FCCOB1 = 15;
          FTFL_FSTAT = FTFL_FSTAT_CCIF;
          while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
          SN = *(uint32_t *)&FTFL_FCCOB7;
    
          #define MAC_OK
          
        #elif defined(HAS_KINETIS_FLASH_FTFE)
          Serial.println("using FTFL_FSTAT_FTFE - vis teensyID.h - see https://github.com/sstaub/TeensyID/blob/master/TeensyID.h");
          
          kinetis_hsrun_disable();
          FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
          *(uint32_t *)&FTFL_FCCOB3 = 0x41070000;
          FTFL_FSTAT = FTFL_FSTAT_CCIF;
          while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
          SN = *(uint32_t *)&FTFL_FCCOBB;
          kinetis_hsrun_enable();
    
          #define MAC_OK
          
        #endif
        
        __enable_irq();
    
        for(uint8_t by=0; by<3; by++) mac[by+3]=(SN >> ((2-by)*8)) & 0xFF;
    
      #endif
    
      #ifdef MAC_OK
        sprintf(teensyMac, "MAC: %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
        Serial.println(teensyMac);
      #else
        Serial.println("ERROR: could not get MAC");
      #endif
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •