UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

WT5001 Class

Module: wt5001

UPM support for the WT5001 Serial MP3 module. This was tested specifically with the Grove Serial MP3 module.
wt5001.jpg

Methods

WT5001

(
  • uart
)
Number

WT5001 constructor

Parameters:

  • uart Number

    Default UART to use (0 or 1)

Returns:

Number:

dataAvailable

(
  • millis
)
Boolean

Checks to see if there is data available for reading

Parameters:

  • millis Number

    Number of milliseconds to wait; 0 means no waiting

Returns:

Boolean:

True if there is data available for reading

readData

(
  • buffer
  • len
)
Number

Reads any available data in a user-supplied buffer. Note: the call blocks until data is available to be read. Use dataAvailable() to determine whether there is data available beforehand, to avoid blocking.

Parameters:

  • buffer String

    Buffer to hold the data read

  • len Number

    Length of the buffer

Returns:

Number:

Number of bytes read

writeData

(
  • buffer
  • len
)
Number

Writes the data in the buffer to the device

Parameters:

  • buffer String

    Buffer to hold the data read

  • len Number

    Length of the buffer

Returns:

Number:

Number of bytes written

setupTty

(
  • baud
)
Boolean

Sets up proper tty I/O modes and the baud rate. The default baud rate is 9,600 (B9600).

Parameters:

  • baud Speed_t

    Desired baud rate.

Returns:

Boolean:

True if successful

checkResponse

(
  • opcode
)
Boolean

Gets a command response and returns its validity

Parameters:

  • opcode WT5001_OPCODE_T

    Opcode to verify

Returns:

Boolean:

True if successful

play

(
  • psrc
  • index
)
Boolean

Plays a file from a source

Parameters:

  • psrc WT5001_PLAYSOURCE_T

    Play source (SD, UDISK, SPI)

  • index Number

    File number to play

Returns:

Boolean:

True if successful

stop

() Boolean

Stops playing

Returns:

Boolean:

True if successful

pause

() Boolean

Pauses the playback or resumes it if already paused

Returns:

Boolean:

True if successful

next

() Boolean

Moves to the next track

Returns:

Boolean:

True if successful

previous

() Boolean

Moves to the previous track

Returns:

Boolean:

True if successful

setVolume

(
  • vol
)
Boolean

Sets the volume. Valid range is 0-31. 0 means mute.

Parameters:

  • vol Number

    undefined

Returns:

Boolean:

True if successful

queue

(
  • index
)
Boolean

Queues a track to play next, when the current song is finished

Parameters:

  • index Number

    File number to queue

Returns:

Boolean:

True if successful

setPlayMode

(
  • pm
)
Boolean

Sets the playback mode

Parameters:

  • pm WT5001_PLAYMODE_T

    Play mode to enable

Returns:

Boolean:

True if successful

insert

(
  • index
)
Boolean

Inserts a track to play immediately, interrupting the current track. When the inserted track is finished, the interrupted track resumes where it was interrupted.

Parameters:

  • index Number

    File number to insert

Returns:

Boolean:

True if successful

setDate

(
  • year
  • month
  • day
)
Boolean

Sets the date of the internal clock

Parameters:

  • year Number

    4-digit year

  • month Number

    Month

  • day Number

    Day

Returns:

Boolean:

True if successful

setTime

(
  • hour
  • minute
  • second
)
Boolean

Sets the time of the internal clock

Parameters:

  • hour Number

    Hour

  • minute Number

    Minute

  • second Number

    Second

Returns:

Boolean:

True if successful

setAlarm

(
  • hour
  • minute
  • second
)
Boolean

Sets the alarm

Parameters:

  • hour Number

    Hour

  • minute Number

    Minute

  • second Number

    Second

Returns:

Boolean:

True if successful

clearAlarm

() Boolean

Clears any alarm that has been set

Returns:

Boolean:

True if successful

getVolume

(
  • vol
)
Boolean

Gets the current volume

Parameters:

  • vol Uint8_t *

    Volume

Returns:

Boolean:

True if successful

getVolume

() Number

Gets the current volume

Returns:

Number:

Volume

getPlayState

(
  • ps
)
Boolean

Gets the current play state: 1 = playing, 2 = stopped, 3 = paused

Parameters:

  • ps Uint8_t *

    Play state

Returns:

Boolean:

True if successful

getPlayState

() Number

Gets the current play state: 1 = playing, 2 = stopped, 3 = paused

Returns:

Number:

Play state

getNumFiles

(
  • psrc
  • numf
)
Boolean

Gets the number of files present on the source device

Parameters:

  • psrc WT5001_PLAYSOURCE_T

    Storage source

  • numf Uint16_t *

    Number of files

Returns:

Boolean:

True if successful

getNumFiles

(
  • psrc
)
Number

Gets the number of files present on the source device

Parameters:

  • psrc WT5001_PLAYSOURCE_T

    Storage source

Returns:

Number:

Number of files

getCurrentFile

(
  • curf
)
Boolean

Gets the index of the current file

Parameters:

  • curf Uint16_t *

    Index of the current file

Returns:

Boolean:

True if successful

getCurrentFile

() Number

Gets the index of the current file

Returns:

Number:

Index of the curretn file

getDate

(
  • year
  • month
  • day
)
Boolean

Gets the device date

Parameters:

  • year Uint16_t *

    4-digit year

  • month Uint8_t *

    Month

  • day Uint8_t *

    Day

Returns:

Boolean:

True if successful

getTime

(
  • hour
  • minute
  • second
)
Boolean

Gets the device time

Parameters:

  • hour Uint8_t *

    Hour

  • minute Uint8_t *

    Minute

  • second Uint8_t *

    Second

Returns:

Boolean:

True if successful

Properties

NONE

Enum WT5001_OPCODE_T

PLAY_SD

Enum WT5001_OPCODE_T

PLAY_SPI

Enum WT5001_OPCODE_T

PLAY_UDISK

Enum WT5001_OPCODE_T

PAUSE

Enum WT5001_OPCODE_T

STOP

Enum WT5001_OPCODE_T

NEXT

Enum WT5001_OPCODE_T

PREVIOUS

Enum WT5001_OPCODE_T

SET_VOLUME

Enum WT5001_OPCODE_T

QUEUE

Enum WT5001_OPCODE_T

PLAY_MODE

Enum WT5001_OPCODE_T

COPY_SD2FLASH

Enum WT5001_OPCODE_T

COPY_UDISK2FLASH

Enum WT5001_OPCODE_T

INSERT_SONG

Enum WT5001_OPCODE_T

SET_DATE

Enum WT5001_OPCODE_T

SET_TIME

Enum WT5001_OPCODE_T

SET_ALARM

Enum WT5001_OPCODE_T

SET_ALARM_DUR

Enum WT5001_OPCODE_T

CLEAR_ALARM

Enum WT5001_OPCODE_T

CLEAR_ALARM_DUR

Enum WT5001_OPCODE_T

READ_VOLUME

Enum WT5001_OPCODE_T

READ_PLAY_STATE

Enum WT5001_OPCODE_T

READ_SPI_NUMF

Enum WT5001_OPCODE_T

READ_SD_NUMF

Enum WT5001_OPCODE_T

READ_UDISK_NUMF

Enum WT5001_OPCODE_T

READ_CUR_FNAME

Enum WT5001_OPCODE_T

READ_CF_CHAR

Enum WT5001_OPCODE_T

READ_DATE

Enum WT5001_OPCODE_T

READ_TIME

Enum WT5001_OPCODE_T

NORMAL

Enum WT5001_PLAYMODE_T

SINGLE_REPEAT

Enum WT5001_PLAYMODE_T

ALL_REPEAT

Enum WT5001_PLAYMODE_T

RANDOM

Enum WT5001_PLAYMODE_T

SD

Enum WT5001_PLAYSOURCE_T

SPI

Enum WT5001_PLAYSOURCE_T

UDISK

Enum WT5001_PLAYSOURCE_T