使用esp32 s3 cam做一个播放器

esp32 s3 cam功能十分强大,集成摄像头屏幕,有8M的内存和16M flash,可以开发很多有趣的东西,比如做机器人的主控,这样的主控还可以做一些视觉训练。

手边有一块esp32 s3 cam的板子和扩展板,刚开始只是接了个屏调试了一下拍照和显示功能,后来想着是不是可以用来播放音乐,查了一下管脚,cam用去了十四个管脚4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18,触摸屏幕也用去了十一个管脚,0,1,2,3, 14,21,41, 42,45, 46,47,板载led灯48,DHT11用2,sd和舵机共用37,38,39,40,剩下的引脚就很少了。好像只剩下usb19,20可用,Rx,TX 43,44可用,内部ram35,36,37可用。就试着使用19,20,21,其实35,36,37更好,如果不使用舵机,接了一个max98357播放网易的在线音乐,最后完全没有问题,这意味着这个除拍照显示,还可以用来播放音乐。如果剩下的管脚可以接个inmp441的话,也可以可以做个ai语音助手的。

记录一下max98357的测试代码,单个模块的测试代码还有很有用处的,在出错时方便排查,测试管脚也是能用到的。

#include "Arduino.h"
#include "WiFiMulti.h"
#include "Audio.h"
#include <Preferences.h>

#define I2S_DOUT 19//37
#define I2S_BCLK 20//36
#define I2S_LRC 21//35

Preferences preferences;
Audio audio;

WiFiMulti wifiMulti;
//String ssid = "FAST_BA74";
//String password = "12345678";
String ssid = "CMCC-y4yk";
String password = "hswy6bks";
const uint16_t port = 8000;
static String music_id = "";

WiFiServer server(port);
TaskHandle_t Task;

void setup() {
  Serial.begin(115200);
  preferences.begin("my-app", false);
  music_id = preferences.getString("music", "1862822901");

  WiFi.mode(WIFI_STA);
  wifiMulti.addAP(ssid.c_str(), password.c_str());
  wifiMulti.run();
  if (WiFi.status() != WL_CONNECTED) {
    WiFi.disconnect(true);
    wifiMulti.run();
  }

  audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
  audio.setVolume(15);  // 0...21
  char httpPath[60];
  sprintf(httpPath, "%s%s%s", "http://music.163.com/song/media/outer/url?id=", music_id, ".mp3");
  Serial.println(httpPath);
  audio.connecttohost(httpPath);  //  128k mp3

  xTaskCreatePinnedToCore(
    Taskcode, /* Task function. */
    "Task",   /* name of task. */
    10000,    /* Stack size of task */
    NULL,     /* parameter of the task */
    0,        /* priority of the task */
    &Task,    /* Task handle to keep track of created task */
    0);       /* pin task to core 1 */
}

void loop() {
  audio.loop();
}

//Taskcode
void Taskcode(void *pvParameters) {
  Serial.println(WiFi.localIP());
  server.begin();
  for (;;) {
    WiFiClient client = server.available();  //尝试建立客户对象
    if (client)                              //如果当前客户可用
    {
      Serial.println("[Client connected]");
      while (client.connected())  //如果客户端处于连接状态
      {
        if (client.available())  //如果有可读数据
        {
          audio.stopSong();//停止播放 
          String c = client.readStringUntil('\n');
          Serial.print(c);
          preferences.putString("music", c);
          preferences.end();
          client.stop();
          esp_restart();
        }
      }
      client.stop();  //结束当前连接: 
      Serial.println("[Client disconnected]");
    }
  }
  vTaskDelay(1000);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值