Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Eslam Fayad
Published

Fruit detection and classification

Fruit quality is the most important factor in protecting students from health problems

IntermediateFull instructions provided912
Fruit detection and classification

Things used in this project

Hardware components

Raspberry Pi 4 Model B
Raspberry Pi 4 Model B
×1
Hackster EEDU Kit - Getting started with IoT
DFRobot Hackster EEDU Kit - Getting started with IoT
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor
Arduino IoT Cloud
Arduino IoT Cloud
Edge Impulse Studio
Edge Impulse Studio

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

camera_back_cover_v002_lJXUFaIVl9.stl

camera_stand_v001_PlLKdnSwJI.stl

Rapberry pi camera cover

Schematics

circuit diagram

Code

Dfplayer pro play code

Arduino
#include <SoftwareSerial.h>

/*!
 *@file play.ino
 *@brief Music Playing Example Program
 *@details  Experimental phenomenon: control MP3 play music, obtain song information
 *@copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 *@license     The MIT license (MIT)
 *@author [fengli](li.feng@dfrobot.com)
 *@version  V1.1
 *@date  2021-10-15
 *@url https://github.com/DFRobot/DFRobot_DF1201S
*/

//#include <Arduino.h>
#include <DFRobot_DF1201S.h>
//#include <SoftwareSerial.h>
//#include <SoftwareSerial.h>

#define DF1201SSerial_TX 17 //D10
#define DF1201SSerial_RX 16 //D11
//software serial pin asssignment////
#define MYPORT_TX 12
#define MYPORT_RX 13

// constants won't change. They're used here to set pin numbers:
const int buttonvolP = D2;     // the number of the pushbutton pin
const int buttonvolN = D3;      // the number of the LED pin

// variables will change:
int buttonP = 0;      int buttonN = 0;    // variable for reading the pushbutton status
EspSoftwareSerial::UART myPort;



//EspSoftwareSerial::UART DF1201SSerial.begin(115200, SWSERIAL_8N1, DF1201SSerial_RX, DF1201SSerial_TX, false);;
//SoftwareSerial DF1201SSerial(2, 3);
HardwareSerial &DF1201SSerial =Serial2;

//SoftwareSerial DF1201SSerial(10, 11);  //RX  TX

DFRobot_DF1201S DF1201S;

unsigned  int vol=20;
void setup(void){
  Serial.begin(115200);
  DF1201SSerial.begin(115200, SERIAL_8N1, DF1201SSerial_RX, DF1201SSerial_TX, false);

  myPort.begin(115200, SWSERIAL_8N1, MYPORT_RX, MYPORT_TX, false);
  if (!myPort) { // If the object did not initialize, then its configuration is invalid
      Serial.println("Invalid EspSoftwareSerial pin configuration, check config"); 
         while (1) { // Don't continue with invalid configuration
             delay (1000);
                   }
            } 
  while(!DF1201S.begin(DF1201SSerial)){  Serial.println("Init failed, please check the wire connection!");
    delay(1000);
  }

 // initialize the pushbutton pin as an input:
  pinMode(buttonvolP, INPUT);
  pinMode(buttonvolN, INPUT);
  /*Set volume to 20*/
  DF1201S.setVol(/*VOL = */vol);
  Serial.print("VOL:");
  /*Get volume*/
  Serial.println(DF1201S.getVol());
  /*Enter music mode*/
  DF1201S.switchFunction(DF1201S.MUSIC);
  /*Wait for the end of the prompt tone */
  delay(2000);
  /*Set playback mode to "repeat all"*/
  DF1201S.setPlayMode(DF1201S.SINGLE);
  Serial.print("PlayMode:");
  /*Get playback mode*/
  Serial.println(DF1201S.getPlayMode());
  
  //Set baud rate to 115200(Need to power off and restart, power-down save)
  //DF1201S.setBaudRate(115200);
  //Turn on indicator LED (Power-down save)
  //DF1201S.setLED(true);
  //Turn on the prompt tone (Power-down save) 
  //DF1201S.setPrompt(true);
  //Enable amplifier chip 
  DF1201S.enableAMP();
  //Disable amplifier chip 
  //DF1201S.disableAMP();
  Serial.println("Start playing");
  /*Start playing*/
  DF1201S.start();
  delay(3000);
  DF1201S.playFileNum(/*File Number = */113);
  delay(3000);
}

void loop(){
  
   buttonP = digitalRead(buttonvolP);
   buttonN = digitalRead(buttonvolN);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonP == HIGH) {
    // turn LED on:
    vol++;
    DF1201S.setVol(/*VOL = */vol);
    Serial.print("VOL:");
  /*Get volume*/
  Serial.println(DF1201S.getVol());
  } else {
    // turn LED off:
    //vol=vol;
  }
  if (buttonN == HIGH) {
    // turn LED on:
    vol--;
    DF1201S.setVol(/*VOL = */vol);
    Serial.print("VOL:");
  /*Get volume*/
  Serial.println(DF1201S.getVol());
  } else {
    // turn LED off:
    //vol=vol;
  }
  if (vol >= 31) {
    vol=20;
  }
  /*
  Serial.println("Pause");
  /*Pause*/
     // DF1201S.pause();
     // delay(3000);
     // Serial.println("Next");
  /*Play the next song*/
    // DF1201S.next();
    // delay(3000);
     // Serial.println("Previous");
  /*Play the previous song*/
    //  DF1201S.last();
    //  delay(3000);
    //  Serial.println("Start playing");
  //Fast forward 10S
     // DF1201S.fastForward(/*FF = */10);
  //Fast Rewind 10S
  //DF1201S.fastReverse(/*FR = */10);
  //Start the song from the 10th second 
  //DF1201S.setPlayTime(/*Play Time = */10);
  
  Serial.print("File number:");
  //Get file number
  Serial.println(DF1201S.getCurFileNumber());
  
  Serial.print("The number of files available to play:");
  //The number of files available to play
  Serial.println(DF1201S.getTotalFile());
  
  Serial.print("The time length the current song has played:");
  //Get the time length the current song has played 
  Serial.println(DF1201S.getCurTime());
  
  Serial.print("The total length of the currently-playing song: ");
  //Get the total length of the currently-playing song 
  Serial.println(DF1201S.getTotalTime());
  Serial.print("The name of the currently-playing file: ");
  //Get the name of the playing file 
  Serial.println(DF1201S.getFileName());
  delay(300);
  //Play the file No.1, the numbers are arranged according to the sequence of the files copied into the U-disk 
  //DF1201S.playFileNum(/*File Number = */1);
  //Play the test.mp3 file in test folder 
  //DF1201S.playSpecFile("/test/test.mp3");
  
 // while(1);
  /*Delete the currently-playing file */
  //DF1201S.delCurFile();
}

Credits

Eslam Fayad

Eslam Fayad

6 projects • 9 followers
Passionate about learning Programming concepts and possess the ability to handle work pressure and customer issues professionally.

Comments