Navigation

    M5Stack Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. creativetabi
    C
    • Continue chat with creativetabi
    • Start new chat with creativetabi
    • Flag Profile
    • Profile
    • Following
    • Followers
    • Blocks
    • Topics
    • Posts
    • Best
    • Groups
    Save
    Saving

    creativetabi

    @creativetabi

    0
    Reputation
    8
    Posts
    1415
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    creativetabi Follow

    Posts made by creativetabi

    • Send accel data from M5Stack Core 2 to TouchDesigner via OSC

      Hi, I'm a complete beginner with programming, and as well as, using M5Stack Core 2 and TouchDesiger.
      Does anyone know how to send accel data from M5Stack Core 2 to TouchDesigner via OSC?

      Below is the code that I copied from several sources.
      I could connect to the WiFi, but no response from TouchDesigner.
      I am not sure what's missing..
      Can someone teach me?

      #include <M5Core2.h>
      #include <WiFi.h>
      #include <WiFiUdp.h>
      #include <OSCBundle.h>
      
      const char *ssid = "***";
      const char *password = "***";
      
      const char *udpAddress ="***";
      const int udpPort = 10000;
      
      WiFiUDP udp;
      
      float accX = 0.0F;
      float accY = 0.0F;
      float accZ = 0.0F;
      
      float gyroX = 0.0F;
      float gyroY = 0.0F;
      float gyroZ = 0.0F;
      
      float pitch = 0.0F;
      float roll = 0.0F;
      float yaw = 0.0F;
      
      float temp = 0.0F;
      
      uint32_t Now = 0;
      uint32_t lastUpdate = 0;
      float deltat = 0.0f;
      
      
      void setup(){
        M5.begin();
        M5.IMU.Init();
        delay(2000);
        Serial.println("*** setup *** aaa ***");
        delay(1000);
      
        WiFi.begin(ssid, password);
        while(WiFi.status() != WL_CONNECTED){
          delay(500);
          M5.Lcd.print(".");
        }
      
        M5.Lcd.println("WiFi Connected");
        M5.Lcd.print("IP address= ");
        M5.Lcd.println(WiFi.localIP());
      }
      
      void loop(){
        M5.update();
        if(WiFi.status() == WL_CONNECTED){
      
          OSCBundle bndl;
      
      
          udp.beginPacket(udpAddress, udpPort);
          bndl.send(udp);
          udp.endPacket();
          bndl.empty();
        }
      
        delay(10);
      
        M5.IMU.getAccelData(&accX,&accY, &accZ);
        M5.IMU.getTempData(&temp);
        deltat = ((Now - lastUpdate)/1000000.0f);
        lastUpdate = Now;
      
        MahonyAHRSupdateIMU(gyroX, gyroY, gyroZ, accX, accY, accZ, &pitch, &roll, &yaw);
        
      }
      
      
      posted in Core 2
      C
      creativetabi
    • How to stop MP3 file from playing (pause / rewind button)?

      Hi,

      Can I ask a question?
      I want to make an m5stack program that would play an mp3 file if I send a trigger via UDP, and would stop if I send a different trigger via UDP.
      I followed some code from:
      http://forum.m5stack.com/topic/143/lesson-6-1-speaker-mp3-player/9

      But when I sent the trigger, the mp3 only played the first second (1s) and kept repeating the same time position. It wouldn't play the entire mp3 song.

      This is the code that I used:


      #include <M5Stack.h>
      #include <WiFi.h>
      #include <WiFiUdp.h>
      #include "AudioFileSourceSD.h"
      #include "AudioFileSourceID3.h"
      #include "AudioGeneratorMP3.h"
      #include "AudioOutputI2S.h"
      #define N 1024

      bool playing = true;
      AudioGeneratorMP3 *mp3;
      AudioFileSourceSD *file;
      AudioOutputI2S *out;
      AudioFileSourceID3 *id3;

      const char* ssid = "wifiname";
      const char* password = "wifipassword";
      const int port = 5555;

      // The udp library class
      WiFiUDP udp;

      void print_wifi_state(){
      M5.Lcd.clear(BLACK); // clear LCD
      M5.Lcd.setTextColor(YELLOW);
      M5.Lcd.setCursor(3, 3);
      M5.Lcd.println("");
      M5.Lcd.println("WiFi connected.");
      M5.Lcd.print("IP address: ");
      M5.Lcd.println(WiFi.localIP());
      M5.Lcd.print("Port: ");
      M5.Lcd.println(port);
      }

      void setup_wifi(){
      M5.Lcd.setTextColor(RED);
      M5.Lcd.setTextSize(2);
      M5.Lcd.setCursor(3, 10);
      M5.Lcd.print("Connecting to ");
      M5.Lcd.println(ssid);

      // setup wifi
      WiFi.mode(WIFI_STA); // WIFI_AP, WIFI_STA, WIFI_AP_STA or WIFI_OFF
      WiFi.begin(ssid, password);
      // WiFi.begin();

      // Connecting ..
      while (WiFi.status() != WL_CONNECTED) {
      delay(100);
      M5.Lcd.print(".");
      }

      // print state
      print_wifi_state();

      udp.begin(port);
      

      }

      void setup() {
      M5.begin();
      M5.Speaker.setVolume(5);
      play('m');
      // setup wifi
      setup_wifi();

      }

      bool play(char dir){
      switch(dir)
      {
      case 'm':
      delete file;
      delete out;
      delete mp3;
      mp3 = NULL;
      file = NULL;
      out = NULL;
      file = new AudioFileSourceSD("/");
      id3 = new AudioFileSourceID3(file);
      out = new AudioOutputI2S(0, 1);
      out->SetOutputModeMono(true);
      mp3 = new AudioGeneratorMP3();
      mp3->begin(id3, out);
      playing = false;
      return true;
      default:
      if(playing){
      play('m');
      return true;
      }
      break;
      }
      mp3->stop();
      delete file;
      delete out;
      delete mp3;
      mp3 = NULL;
      file = NULL;
      out = NULL;
      file = new AudioFileSourceSD("/RainDrizzle.mp3");
      id3 = new AudioFileSourceID3(file);
      id3->seek(trackList->timePos, 1);
      out = new AudioOutputI2S(0, 1);
      out->SetOutputModeMono(true);
      mp3 = new AudioGeneratorMP3();
      mp3->begin(id3, out);
      playing = true;

      return true;
      }

      void loop() {
      char packetBuffer[N];
      int packetSize = udp.parsePacket();

      // get packet
      if (packetSize){

      int len = udp.read(packetBuffer, packetSize);
      
      if (len > 0){
        packetBuffer[len] = '\0'; // end
      }
      

      }

      if(strcmp(packetBuffer,"start")==0){
      // print param
      M5.Lcd.clear(BLACK);
      M5.Lcd.setCursor(3, 3);
      M5.Lcd.setTextColor(GREEN);
      M5.Lcd.println(packetBuffer);
      
      play('t');
      
      }
      
      if(strcmp(packetBuffer,"stop")==0){
      M5.Lcd.clear(BLACK);
      M5.Lcd.setCursor(3, 3);
      M5.Lcd.setTextColor(GREEN);
      M5.Lcd.println(packetBuffer);
      play('m');
      }
      
      if(playing){
        if(mp3->isRunning()){
          if(!mp3->loop()){
            mp3->stop();
            playing = false;
          }
        }
        else{
          delay(1000);
        }
      

      }
      M5.update();
      }


      Please advise if anything's wrong in the code.

      Thank you in advance.

      posted in PROJECTS
      C
      creativetabi
    • RE: Lesson 6.1. Speaker. MP3 player

      Hi @Dimi, thanks for the amazing tutorial.

      Can I ask a question?
      I want to make an m5stack program that would play an mp3 file if I send a trigger via UDP, and would stop if I send a different trigger via UDP.
      I followed some of your code.

      But when I sent the trigger, the mp3 only played the first second and kept repeating the same time position. It wouldn't play the entire mp3 song.

      This is the code that I used:


      #include <M5Stack.h>
      #include <WiFi.h>
      #include <WiFiUdp.h>
      #include "AudioFileSourceSD.h"
      #include "AudioFileSourceID3.h"
      #include "AudioGeneratorMP3.h"
      #include "AudioOutputI2S.h"
      #define N 1024

      bool playing = true;
      AudioGeneratorMP3 *mp3;
      AudioFileSourceSD *file;
      AudioOutputI2S *out;
      AudioFileSourceID3 *id3;

      const char* ssid = "wifiname";
      const char* password = "wifipassword";
      const int port = 5555;

      // The udp library class
      WiFiUDP udp;

      void print_wifi_state(){
      M5.Lcd.clear(BLACK); // clear LCD
      M5.Lcd.setTextColor(YELLOW);
      M5.Lcd.setCursor(3, 3);
      M5.Lcd.println("");
      M5.Lcd.println("WiFi connected.");
      M5.Lcd.print("IP address: ");
      M5.Lcd.println(WiFi.localIP());
      M5.Lcd.print("Port: ");
      M5.Lcd.println(port);
      }

      void setup_wifi(){
      M5.Lcd.setTextColor(RED);
      M5.Lcd.setTextSize(2);
      M5.Lcd.setCursor(3, 10);
      M5.Lcd.print("Connecting to ");
      M5.Lcd.println(ssid);

      // setup wifi
      WiFi.mode(WIFI_STA); // WIFI_AP, WIFI_STA, WIFI_AP_STA or WIFI_OFF
      WiFi.begin(ssid, password);
      // WiFi.begin();

      // Connecting ..
      while (WiFi.status() != WL_CONNECTED) {
      delay(100);
      M5.Lcd.print(".");
      }

      // print state
      print_wifi_state();

      udp.begin(port);
      

      }

      void setup() {
      M5.begin();
      M5.Speaker.setVolume(5);
      play('m');
      // setup wifi
      setup_wifi();

      }

      bool play(char dir){
      switch(dir)
      {
      case 'm':
      delete file;
      delete out;
      delete mp3;
      mp3 = NULL;
      file = NULL;
      out = NULL;
      file = new AudioFileSourceSD("/");
      id3 = new AudioFileSourceID3(file);
      out = new AudioOutputI2S(0, 1);
      out->SetOutputModeMono(true);
      mp3 = new AudioGeneratorMP3();
      mp3->begin(id3, out);
      playing = false;
      return true;
      default:
      if(playing){
      play('m');
      return true;
      }
      break;
      }
      mp3->stop();
      delete file;
      delete out;
      delete mp3;
      mp3 = NULL;
      file = NULL;
      out = NULL;
      file = new AudioFileSourceSD("/RainDrizzle.mp3");
      id3 = new AudioFileSourceID3(file);
      id3->seek(trackList->timePos, 1);
      out = new AudioOutputI2S(0, 1);
      out->SetOutputModeMono(true);
      mp3 = new AudioGeneratorMP3();
      mp3->begin(id3, out);
      playing = true;

      return true;
      }

      void loop() {
      char packetBuffer[N];
      int packetSize = udp.parsePacket();

      // get packet
      if (packetSize){

      int len = udp.read(packetBuffer, packetSize);
      
      if (len > 0){
        packetBuffer[len] = '\0'; // end
      }
      

      }

      if(strcmp(packetBuffer,"start")==0){
      // print param
      M5.Lcd.clear(BLACK);
      M5.Lcd.setCursor(3, 3);
      M5.Lcd.setTextColor(GREEN);
      M5.Lcd.println(packetBuffer);
      
      play('t');
      
      }
      
      if(strcmp(packetBuffer,"stop")==0){
      M5.Lcd.clear(BLACK);
      M5.Lcd.setCursor(3, 3);
      M5.Lcd.setTextColor(GREEN);
      M5.Lcd.println(packetBuffer);
      play('m');
      }
      
      if(playing){
        if(mp3->isRunning()){
          if(!mp3->loop()){
            mp3->stop();
            playing = false;
          }
        }
        else{
          delay(1000);
        }
      

      }
      M5.update();
      }


      Thank you in advance.

      posted in Lessons and Guides
      C
      creativetabi
    • RE: M5Stack with External Speaker

      @lukasmaximus Yes.. I want to make an audio-haptic installation for a school project. :) And now I'm trying to make it wireless. By any chance, do you know how to send data from MAX/MSP to M5Stack (via udp, WiFi)?

      posted in PROJECTS
      C
      creativetabi
    • RE: M5Stack with External Speaker

      Hi @lukasmaximus, I'm using the black core M5Stack.
      I've tried what you suggested and now it's ok already. :)
      Thank you so much for your help.

      posted in PROJECTS
      C
      creativetabi
    • M5Stack with External Speaker

      Hi,

      I'm a newbie in M5Stack.
      I would like to know if it's possible to turn off the M5Stack internal speaker and connect it to an external speaker (or vibrotransducer)?

      I use the following vibrotransducer as my speaker: http://www.acouve.co.jp/product/pd_vp2.html
      And PAM8403 amplifier.

      Can anyone teach me how to connect all the parts with a schematic diagram (if possible)?

      Thank you in advance.

      Best regards!

      posted in PROJECTS
      C
      creativetabi