Difference between revisions of "MClock (X02)"

From Microduino Wiki
Jump to: navigation, search
(Created page with "right|thumb|mClock Project Build =About= This project uses the '''Real Time Clock (RTC) module''' to keep track of time. The time i...")
 
(Program)
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[File:mClock Project.jpg|right|thumb|mClock Project Build]]
+
[[File:MClock_X02_Top_View.jpg|right|thumb|mClock Project Build]]
 
=About=
 
=About=
This project uses the '''[[MCookie-RTC|Real Time Clock (RTC) module]]''' to keep track of time. The time is retrieved from the RTC module and displayed on an '''[[mCookie-OLED|OLED module]]'''.  This project is an adaptation of the [[MWatch]] project in the first generation mCookie Maker Kits.
+
This project uses the '''[[MCookie-RTC|Real Time Clock (RTC) module]]''' to keep track of time. The time is retrieved from the RTC module and displayed on an '''[[mCookie-OLED|OLED module]]'''.  This project is an adaptation of the '''[[MWatch]]''' project from the first generation mCookie Maker Kits.
  
 
This project was designed for the second generation mCookie Maker kits (202 Advanced and 302 Expert kits).
 
This project was designed for the second generation mCookie Maker kits (202 Advanced and 302 Expert kits).
Line 13: Line 13:
  
 
=Build=
 
=Build=
==Sound File==
 
*There should be a MicroSD card and reader included in 202 and 302 kits.
 
*Put an MP3 file onto the root of your MicroSD Card with the name '''a.mp3''' and '''b.mp3'''. These are the files this program looks to play when activated. It can be a sound effect or a song (such as Alan Walker's Fade or Alan Walker's Alone).
 
*It is possible to have multiple sound files. Read the section on '''[[#Tweaking]]''' to learn about how to change the code to work with more than 2 files.
 
 
 
==Assembly==
 
==Assembly==
'''NOTE''': When connecting sensor wires, push on the plastic connector and not on the wires. Pushing on the wire can damage them.
+
#Stack all three of the modules, mCookie Core, mCookie RTC, and mCookie OLED onto mBattery. Ensure that mCookie OLED is on top of the stack.
#Connect a Touch Button to the Sensor Hub on Pin 2/3. This will be the '''Volume Up / Next Track''' button.
 
#Connect a Touch Button to the Sensor Hub on Pin 4/5. This will be the '''Play / Pause''' button.
 
#Connect a Touch Button to the Sensor Hub on Pin 6/7. This will be the '''Volume Down / Previous Track''' button.
 
#Connect a Micrphone Sensor to the Sensor Hub on Pin A6/A7.
 
#Connect the Two Speakers to the Audio Pro Module.
 
#Insert the MicroSD card with the '''a.mp3''' and '''b.mp3''' file into the MicroSD Module.
 
#Create two stacks containing:
 
##'''(Bottom of Stack)''' MicroSD Module | Audio Pro Module | Sensor Hub '''(Top of Stack)'''
 
##'''(Bottom of Stack)''' Core | LED Matrix '''(Top of Stack)'''
 
#Stack the two stacks onto the mBattery
 
 
#Plug in the MicroUSB cable to the mBattery to a computer.
 
#Plug in the MicroUSB cable to the mBattery to a computer.
  
Line 35: Line 20:
 
1. Connect [[mCookie-Core|mCookie Core]] to the PC with the USB Cable. Open the Microduino IDE.
 
1. Connect [[mCookie-Core|mCookie Core]] to the PC with the USB Cable. Open the Microduino IDE.
  
2. Copy and paste the code below and upload.
+
2. Download the project file and unzip: '''<big>[[File:mClock_X02.zip]]</big>'''.
 +
*Using the Microduino IDE and go to '''File > Open...''' and navigate to the unzipped folder. Open the '''mClock_X02.ino''' file.  
  
<source lang="cpp">
+
3. Go to the '''userDef.h''' tab to configure variables for the date and time. Visit the [[#Tweaking]] section. Ensure that '''TIME_SET = true'''.
  
</source>
+
4. Select the board, processor and port:
3. Select the board, processor and port:
 
 
*Go to '''Tools > Board'''  and select '''Microduino/mCookie-Core (328p)'''
 
*Go to '''Tools > Board'''  and select '''Microduino/mCookie-Core (328p)'''
 
*Go to '''Tools > Processor''' and select '''Atmega328P16M,5V'''
 
*Go to '''Tools > Processor''' and select '''Atmega328P16M,5V'''
 
*Go to '''Tools > Port''' and select the available port
 
*Go to '''Tools > Port''' and select the available port
4. Upload the program by clicking on the '''right arrow icon''' on the top left of the window. Or under '''Sketch > Upload'''.
 
  
 
'''NOTE''': If not using the default Core module included in the kits, please follow the '''[[Selecting_board,_processor,_and_port|selecting the board and processor guide]]'''.
 
'''NOTE''': If not using the default Core module included in the kits, please follow the '''[[Selecting_board,_processor,_and_port|selecting the board and processor guide]]'''.
==Debugging==
 
*Open the Serial monitor. Information on detecting the the Audio module (successfully or failed) and start / stop playing of music will be outputted.
 
  
==Tweaking==
+
5. Upload the program by clicking on the '''right arrow icon''' on the top left of the window. Or under '''Sketch > Upload'''.
Variables can be edited to change the threshold / detection value for various functions to better fine tune to your environment.  
+
 
 +
6. Once the program is uploaded. Set the '''TIME_SET = false''', this will disable writing the time on each power up. Thus, preserving the time previously written. Re-upload the sketch.
 +
 
 +
=Debugging=
 +
 
 +
=Tweaking=
 +
'''DEBUG''' uncomment to debug.
 +
 
 +
 
 +
'''SET_TIME''' allows the time to be set on the Real Time Module.
 +
*true or 1 will set a new time on the RTC module each time the Core module starts up.
 +
*false or 0 will not set a new time.
 +
*Recommended to set to false and re-upload once time has been set.
 +
 
 +
 
 +
'''DATE_YEAR''' sets the last two digits of the year. Year: 20__
 +
 
 +
'''DATE_MONTH''' sets the month. Month: Jan=1, Feb=2...Dec=12
 +
 
 +
'''DATE_DAY'''  sets the day in the month
  
'''DEBUG''' will enable debugging mode. Which outputs information to the Serial Port.
+
'''DATE_WEEKDAY''' sets the weekday value. Weekday: Sun=0, Mon=1...Sat=6
  
'''NUM_SONGS''' determines the number of tracks the program will access.
+
'''TIME_HOUR''' sets the hour.
  
'''SONGS[NUM_SONGS]''' is an array that contains the tracks the program will access. To add additional track add the track name to the array definition. Ensure that the files are in the MicroSD card. Ensure to update '''NUM_SONGS''' with the appropriate number of songs.
+
'''TIME_MINUTE''' sets the minute.
*Example 1:
 
<source lang="cpp">
 
const static int NUM_SONGS = 2;
 
const String SONGS[NUM_SONGS] = {"a.mp3", "b.mp3"};
 
</source>
 
*Example 2:
 
<source lang="cpp">
 
const static int NUM_SONGS = 5;
 
const String SONGS[NUM_SONGS] = {"a.mp3", "b.mp3", "TrackPi.mp3", "TrackIV.mp3", "Track5.mp3"};
 
</source>
 
  
'''SKIP_TIME''' determines the time in milliseconds (1000 milliseconds = 1 second) in which to hold down the '''Volume Up / Skip Track touch button''' or '''Volume Down / Previous Track touch button''' in order to register as a '''Skip Track''' or '''Previous Track'''.
+
'''TIME_SECOND''' sets the second.
  
'''AMBIENT_THRESHOLD''' determines the Microphone Sensor sound level which is ignored and is treated as ambient noise. Which means there values under this value will not produce an output to the LED Matrix.
+
'''STRING_MESSAGE''' sets the scrolling message on display. Long messages will overlap.
  
'''MAX_THRESHOLD''' determines the Microphone Sensor sound level which is considered the max. This enables better scaling of the LED Matrix brightness output.
+
=Troubleshooting=
 +
<blockquote>My time resets each time I power on mClock!</blockquote>
 +
If the '''SET_TIME''' is true under '''userDef.h''', then the time will be set on power up.
 +
*Configure the date / time on '''userDef.h''' with the '''SET_TIME''' = true. Then upload.
 +
*After upload is complete. Change '''SET_TIME''' = false. Re-upload. This will disable setting the time on power up.
 +
 
 +
<blockquote>I am having problems uploading sketches / examples that use the RTC module!</blockquote>
 +
There is an issue with the incorrect and outdated software library included in the Microduino software package. To fix it, please follow the guide below:
 +
#Download the correct library file from here: https://wiki.microduino.cc/images/9/90/Rtc_pcf8563.zip
 +
#In the Microduino IDE go to Sketch->Add .ZIP library...
 +
#Navigate to the downloaded file and select the "Rtc_pcf8563.zip". Then click Choose on the bottom right.
 +
#Now the IDE should use the correct library version and should be able to compile the program.
  
 
=Usage=
 
=Usage=
The first track should play automatically on start up. The Microphone picks up the sound levels and outputs them accordingly to the LED Matrix.
+
Turn on the project and the time stored on the Real Time Clock (RTC) module will be retrieved and displayed on the OLED screen. Powering off the project will maintain the time since the Real Time Clock (RTC) has a capacitor that enables keeping track of the time even when the power source is off. (Please comment out the '''setRtcTime''' line so that the time does not get overwritten every time the Core module starts up).
 
 
Control of the music box is as the following:
 
*'''Play / Pause''' Button  - Quick tap will play or pause the current track.
 
*'''Volume Up / Skip Track''' Button  - Quick tap to increase volume. Hold for more than 1 second (default) then release to skip track.
 
*'''Volume Down / Previous Track''' Button - Quick tap to decrease volume. Hold for more than 1 second (default) then release to go to previous track.
 

Latest revision as of 23:36, 3 May 2017

mClock Project Build

About

This project uses the Real Time Clock (RTC) module to keep track of time. The time is retrieved from the RTC module and displayed on an OLED module. This project is an adaptation of the MWatch project from the first generation mCookie Maker Kits.

This project was designed for the second generation mCookie Maker kits (202 Advanced and 302 Expert kits).

Required Materials

  • 1 x mCookie Core
  • 1 x mBattery (202/302 Kit)
  • 1 x Real Time Clock (RTC) Module
  • 1x mCookie OLED Module
  • 1 x MicroUSB Cable

Build

Assembly

  1. Stack all three of the modules, mCookie Core, mCookie RTC, and mCookie OLED onto mBattery. Ensure that mCookie OLED is on top of the stack.
  2. Plug in the MicroUSB cable to the mBattery to a computer.

Program

1. Connect mCookie Core to the PC with the USB Cable. Open the Microduino IDE.

2. Download the project file and unzip: File:MClock X02.zip.

  • Using the Microduino IDE and go to File > Open... and navigate to the unzipped folder. Open the mClock_X02.ino file.

3. Go to the userDef.h tab to configure variables for the date and time. Visit the #Tweaking section. Ensure that TIME_SET = true.

4. Select the board, processor and port:

  • Go to Tools > Board and select Microduino/mCookie-Core (328p)
  • Go to Tools > Processor and select Atmega328P16M,5V
  • Go to Tools > Port and select the available port

NOTE: If not using the default Core module included in the kits, please follow the selecting the board and processor guide.

5. Upload the program by clicking on the right arrow icon on the top left of the window. Or under Sketch > Upload.

6. Once the program is uploaded. Set the TIME_SET = false, this will disable writing the time on each power up. Thus, preserving the time previously written. Re-upload the sketch.

Debugging

Tweaking

DEBUG uncomment to debug.


SET_TIME allows the time to be set on the Real Time Module.

  • true or 1 will set a new time on the RTC module each time the Core module starts up.
  • false or 0 will not set a new time.
  • Recommended to set to false and re-upload once time has been set.


DATE_YEAR sets the last two digits of the year. Year: 20__

DATE_MONTH sets the month. Month: Jan=1, Feb=2...Dec=12

DATE_DAY sets the day in the month

DATE_WEEKDAY sets the weekday value. Weekday: Sun=0, Mon=1...Sat=6

TIME_HOUR sets the hour.

TIME_MINUTE sets the minute.

TIME_SECOND sets the second.

STRING_MESSAGE sets the scrolling message on display. Long messages will overlap.

Troubleshooting

My time resets each time I power on mClock!

If the SET_TIME is true under userDef.h, then the time will be set on power up.

  • Configure the date / time on userDef.h with the SET_TIME = true. Then upload.
  • After upload is complete. Change SET_TIME = false. Re-upload. This will disable setting the time on power up.
I am having problems uploading sketches / examples that use the RTC module!

There is an issue with the incorrect and outdated software library included in the Microduino software package. To fix it, please follow the guide below:

  1. Download the correct library file from here: https://wiki.microduino.cc/images/9/90/Rtc_pcf8563.zip
  2. In the Microduino IDE go to Sketch->Add .ZIP library...
  3. Navigate to the downloaded file and select the "Rtc_pcf8563.zip". Then click Choose on the bottom right.
  4. Now the IDE should use the correct library version and should be able to compile the program.

Usage

Turn on the project and the time stored on the Real Time Clock (RTC) module will be retrieved and displayed on the OLED screen. Powering off the project will maintain the time since the Real Time Clock (RTC) has a capacitor that enables keeping track of the time even when the power source is off. (Please comment out the setRtcTime line so that the time does not get overwritten every time the Core module starts up).