I'm using a Teensy 3.2, a DY-SV5W board, and the DYPlayer library. There's some other odd hardware in the project, but that's all been working no problem. I'm basically making a very very silly mp3 player that uses old hardware I have lying around.
It's got 2 strips of NeoPixels, a RRD Full Graphic Smart Controller, and some tactile switches. Those all work.
But when I try to get the DY board working, it just ... doesn't. Problem 1 - the speaker I'm using seems to be too beefy. Not the end of the world, I'll find another. If I plug in headphones, they work... but only until I power cycle?!?
Basically, if I flash the firmware (not even having made changes, just flashing it), the board starts playing an MP3 through the headphones. But if I unplug the power, and re-connect the power, nothing. It's utterly baffling to me.
I've tried manually "starting" the Serial1 port in code, but nothing.
It's got 2 strips of NeoPixels, a RRD Full Graphic Smart Controller, and some tactile switches. Those all work.
But when I try to get the DY board working, it just ... doesn't. Problem 1 - the speaker I'm using seems to be too beefy. Not the end of the world, I'll find another. If I plug in headphones, they work... but only until I power cycle?!?
Basically, if I flash the firmware (not even having made changes, just flashing it), the board starts playing an MP3 through the headphones. But if I unplug the power, and re-connect the power, nothing. It's utterly baffling to me.
Code:
/*
To do:
- Dyplayer
-- wired. pins 0/1. pin 2 for busy
- SD support
- txtfile per song (songs are 00001.MP3 ~ 65535.MP3)
-- matching txt files:(00001.NFO)
--- Artist
--- Song Name
--- Length in milliseconds
--- BPM
(00001.XBM) = Album Art
--- need to learn to scroll subset of screen
*/
#include <Arduino.h>
#include <U8g2lib.h>
#include <SdFat.h>
#include <FastLED.h>
#include <Automaton.h>
#include <DYPlayerArduino.h>
#include "bitmaps.h"
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
#define NUM_LEDS 16
#define LED_DATA_PIN 4
int current_mode = 1;
long currentframe;
long nextframe;
CRGB leds[NUM_LEDS];
int ghue = 0;
Atm_encoder dial;
Atm_button dial_btn;
Atm_button volup;
Atm_button voldn;
U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0,14,7,9); // rot / clock / data/ cs
// can I use 14/7/9?
// End of constructor list
int piezo = 23;
DY::Player mp3(&Serial1);
void beep(int time) {
digitalWrite(piezo,HIGH);
delay(time);
digitalWrite(piezo,LOW);
}
void u8g2_prepare(void) {
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.setFontRefHeightExtendedText();
u8g2.setDrawColor(1);
u8g2.setFontPosTop();
u8g2.setFontDirection(0);
}
void progress_bar(uint8_t max, uint8_t current, uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t rounded = 0) {
// draws a progress bar
// bar is 1px inset of the W/H to look good
uint8_t max_length = w-4;
uint8_t max_height = h-4;
uint8_t mapped = map(current, 0, max, 0, max_length);
if(rounded) {
u8g2.drawRFrame(x,y,w,h,3);
u8g2.drawRBox(x+2,y+2,mapped, max_height, 1);
} else {
u8g2.drawFrame(x,y,w,h);
u8g2.drawBox(x+2,y+2,mapped, max_height);
}
}
void layout() {
u8g2.drawRFrame(0,0,48,48,3);
u8g2.drawRFrame(0,50,128,14,3);
u8g2.drawStr(14,24, "LOGO");
u8g2.drawStr(40,51,"progress");
}
void onosendai_logo() {
static uint8_t progress = 0;
if(progress <= 95) {
progress = progress + 5;
} else {
progress = 100;
current_mode++;
}
u8g2.setBitmapMode(false);
u8g2.drawXBM(19,5,onosendai_width, onosendai_height, onosendai_bits);
/* todo: Loading bar*/
progress_bar(100,progress,0,52,128,10,1);
}
void dial_up () {
ghue = ghue +50;
fill_rainbow_circular(leds, NUM_LEDS, ghue);
FastLED.show();
beep(25);
}
void dial_down () {
ghue = ghue-50;
fill_rainbow_circular(leds, NUM_LEDS, ghue);
FastLED.show();
beep(25);
}
void volume_up(int idx, int v, int up) {
}
void volume_down(int idx, int v, int up) {
}
void setup(void) {
FastLED.addLeds<NEOPIXEL, LED_DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(16);
dial.begin(5,6)
.onChange([] (int idx, int v, int up){
if(up) {
dial_up();
} else {
dial_down();
}
});
volup.begin(19)
.onPress(volume_up);
voldn.begin(20)
.onPress(volume_down);
mp3.begin();
mp3.setVolume(30);
mp3.setCycleMode(DY::PlayMode::Repeat);
mp3.playSpecifiedDevicePath(DY::Device::Sd, "/00002.MP3");
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(10, 0);
digitalWrite(9, 0);
pinMode(piezo, OUTPUT);
u8g2.begin();
u8g2_prepare();
u8g2.clearBuffer();
}
void loop(void) {
automaton.run();
u8g2.clearBuffer();
switch(current_mode) {
case 1: // first run
onosendai_logo();
break;
case 2:
layout();
break;
default:
break;
}
u8g2.sendBuffer();
}
I've tried manually "starting" the Serial1 port in code, but nothing.