YX5300 connected to Giga R1

Hello,

I have uploaded the code below and get no errors.

When I push the play button there is no sound from the mp3 on the sd-card.

The tracks are named 001.mp3, 002.mp3 and 003.mp3 and are in the root of the sd-card.

The connections are: RX of YX5300 to TX (pin 1) and TX of YX5300 to RX(pin 0).

When I monitor the packet it looks oké.

Set volume at 20.

Packet: 0x7E 0xFF 0x06 0x06 0x00 0x00 0x14 0xEF 

Play with index

Packet: 0x7E 0xFF 0x06 0x03 0x00 0x00 0x01 0xEF 

Next track

Packet: 0x7E 0xFF 0x06 0x03 0x00 0x00 0x02 0xEF 

Stop playing

Packet: 0x7E 0xFF 0x06 0x16 0x00 0x00 0x00 0xEF 
#include <Arduino_H7_Video.h>
#include <Arduino_GigaDisplayTouch.h>
#include <lvgl.h>

Arduino_H7_Video Display(800, 480, GigaDisplayShield);
Arduino_GigaDisplayTouch TouchDetector;

// #define mp3 Serial1

lv_obj_t *labelTrack;
lv_obj_t *sliderVolume;

uint16_t track = 1;
uint8_t volume = 20;
bool playing = false;

void sendCommand(uint8_t cmd, uint8_t p1, uint8_t p2) {
  uint8_t packet[8] = { 0x7E, 0xFF, 0x06, cmd, 0x00, p1, p2, 0xEF };

  Serial1.write(packet, 8);

  Serial.print("Packet: ");

  for (int i = 0; i < 8; i++) {
    Serial.print("0x");
    if (packet[i] < 0x10) Serial.print("0"); // leading zero
    Serial.print(packet[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
}

void playTrack(uint16_t t) {
  sendCommand(0x03, t >> 8, t & 0xFF);
  playing = true;
}

void pauseTrack() {
  if (playing = true) {
    sendCommand(0x0E, 0, 0);
    playing = false;
  }
  else resumeTrack();
}

void resumeTrack() {
  sendCommand(0x0D, 0, 0);
  playing = true;
}

void nextTrack() {
  track++;
  playTrack(track);
  updateTrack();
}

void prevTrack() {
  if (track > 1) track--;
  playTrack(track);
  updateTrack();
}

void stopTrack() {
  sendCommand(0x16, 0, 0);
  playing = false;
}

void setVolume(uint8_t v) {
  volume = v;
  sendCommand(0x06, 0, v);
}

void updateTrack() {
  char buf[32];
  sprintf(buf, "Track %03d", track);
  lv_label_set_text(labelTrack, buf);
}

void event_play(lv_event_t *e) {
  playTrack(track);
}

void event_prev(lv_event_t *e) {
  prevTrack();
}

void event_next(lv_event_t *e) {
  nextTrack();
}

void event_pause(lv_event_t *e) {
  pauseTrack();
}

void event_stop(lv_event_t *e) {
  stopTrack();
}

void event_volume(lv_event_t *e) {
  int v = lv_slider_get_value(sliderVolume);
  setVolume(v);
}

void build_ui() {
  lv_obj_t *title = lv_label_create(lv_scr_act());
  lv_label_set_text(title, "GIGA MP3 Player");
  lv_obj_align(title, LV_ALIGN_TOP_MID, 0, 10);
  lv_obj_set_style_text_font(title, &lv_font_montserrat_34, LV_PART_MAIN || LV_STATE_DEFAULT);

  labelTrack = lv_label_create(lv_scr_act());
  lv_label_set_text(labelTrack, "Track 001");
  lv_obj_align(labelTrack, LV_ALIGN_TOP_MID, 0, 50);

  lv_obj_t *btnPrev = lv_btn_create(lv_scr_act());
  lv_obj_set_size(btnPrev, 100, 60);
  lv_obj_align(btnPrev, LV_ALIGN_CENTER, -240, 0);
  lv_obj_add_event_cb(btnPrev, event_prev, LV_EVENT_CLICKED, NULL);

  lv_obj_t *lblPrev = lv_label_create(btnPrev);
  lv_label_set_text(lblPrev, LV_SYMBOL_PREV);
  lv_obj_set_style_text_font(lblPrev, &lv_font_montserrat_28, LV_PART_MAIN || LV_STATE_DEFAULT);
  lv_obj_center(lblPrev);

  lv_obj_t *btnPlay = lv_btn_create(lv_scr_act());
  lv_obj_set_size(btnPlay, 100, 60);
  lv_obj_align(btnPlay, LV_ALIGN_CENTER, -120, 0);
  lv_obj_add_event_cb(btnPlay, event_play, LV_EVENT_CLICKED, NULL);

  lv_obj_t *lblPlay = lv_label_create(btnPlay);
  lv_label_set_text(lblPlay, LV_SYMBOL_PLAY);
  lv_obj_set_style_text_font(lblPlay, &lv_font_montserrat_28, LV_PART_MAIN || LV_STATE_DEFAULT);
  lv_obj_center(lblPlay);

  lv_obj_t *btnNext = lv_btn_create(lv_scr_act());
  lv_obj_set_size(btnNext, 100, 60);
  lv_obj_align(btnNext, LV_ALIGN_CENTER, 120, 0);
  lv_obj_add_event_cb(btnNext, event_next, LV_EVENT_CLICKED, NULL);

  lv_obj_t *lblNext = lv_label_create(btnNext);
  lv_label_set_text(lblNext, LV_SYMBOL_NEXT);
  lv_obj_set_style_text_font(lblNext, &lv_font_montserrat_28, LV_PART_MAIN || LV_STATE_DEFAULT);
  lv_obj_center(lblNext);

  lv_obj_t *btnPause = lv_btn_create(lv_scr_act());
  lv_obj_set_size(btnPause, 100, 60);
  lv_obj_align(btnPause, LV_ALIGN_CENTER, 0, 0);
  lv_obj_add_event_cb(btnPause, event_pause, LV_EVENT_CLICKED, NULL);

  lv_obj_t *lblPause = lv_label_create(btnPause);
  lv_label_set_text(lblPause, LV_SYMBOL_PAUSE);
  lv_obj_set_style_text_font(lblPause, &lv_font_montserrat_28, LV_PART_MAIN || LV_STATE_DEFAULT);
  lv_obj_center(lblPause);

  lv_obj_t *btnStop = lv_btn_create(lv_scr_act());
  lv_obj_set_size(btnStop, 100, 60);
  lv_obj_align(btnStop, LV_ALIGN_CENTER, 240, 0);
  lv_obj_add_event_cb(btnStop, event_stop, LV_EVENT_CLICKED, NULL);

  lv_obj_t *lblStop = lv_label_create(btnStop);
  lv_label_set_text(lblStop, LV_SYMBOL_STOP);
  lv_obj_set_style_text_font(lblStop, &lv_font_montserrat_28, LV_PART_MAIN || LV_STATE_DEFAULT);
  lv_obj_center(lblStop);

  sliderVolume = lv_slider_create(lv_scr_act());
  lv_obj_set_width(sliderVolume, 400);
  lv_obj_align(sliderVolume, LV_ALIGN_BOTTOM_MID, 0, -40);
  lv_slider_set_range(sliderVolume, 0, 30);
  lv_slider_set_value(sliderVolume, volume, LV_ANIM_OFF);
  lv_obj_add_event_cb(sliderVolume, event_volume, LV_EVENT_VALUE_CHANGED, NULL);
}

void setup() {
  Serial.begin(9600);

  Serial1.begin(9600);
  sendCommand(0x09, 0x00, 0x02);

  Display.begin();
  TouchDetector.begin();

  lv_init();

  build_ui();

  setVolume(volume);
}

void loop() {
  lv_timer_handler();
  delay(5);
}

joined ground ?

Giga R1 is a 3.3V device, what about your YX5300?

It is connected to gnd and 5V of the Giga and de red led on the yx5300 is on.

Is your YX5300 a 5V or a 3.3V device ? (What voltage will be set on its Tx if the module sends a 1 ?)

The voltage on Tx is 3.1V.

I found the problem.

I connected the Tx → Rx and Rx → Tx.

That didn’t work and after seeing some pictures of the YX5300 board I saw that the lables on my board were different than on the pictures.

So I chanced the connections (Tx → Tx, Rx → Rx) and now my board is working like it should.

thanks for sharing the solution