Monthly Archives: May 2014

Lego EV3COMPOS3R II plays Bach – video published on youtube

See and hear EV3COMPOS3R II in action here

Advertisements

LEGO EV3COMPOS3R II improved version with supplied music packs

The New Education Set version starting screenEDDIISPLASH

The new Retail Set version starting screenRETIISPLASH

Having used the original EV3COMPOS3R extensively, I decided to improve the program in the light of various issues which came to light. I have also taken the opportunity to improve and update the documentation supplied with each version of the project.

First I found an issue with the timing of various tunes which didn’t play back accurately. This was because there is a finite overhead time to traverse the playback loop which presents the notes in turn to the sound module. This has a greater proportional impact on sequences of short notes compared to those of longer notes. This can give the impression that the longer notes are “hurrying” and playing too fast. After some experimentation I decided to subtract a small time value from every note played and this seems to give a better result, although perhaps not quite so good if you have very fast (short) notes, as they become a little clipped. The subtraction concerned is in the new bkPlayOneNote at the end, and you can alter the value, or set it to zero if you prefer that. I have it at 0.036

Secondly, I found that occasionally I inadvertently deleted the tune in memory (M button on the Menu Choices). This was exasperating If I hadn’t already saved the tune. I introduced a safety feature which required the Note Record Pushbutton on the model to be held down while the M button is pushed, so it is not possible to do this inadvertently. I made the same adjustment to the Note Delete function, but also changed this so that pressing the U button WITHOUT holding down the Note Record Push Button now plays the last note recorded. This is a useful addition if you can’t remember exactly where you got to in entering a tune.

Thirdly, although it works OK in the first version of EV3COMPOS3R I decided to remove the mechanism whereby moving one of the motor arms was used to exit the Menu loop. This was done in the bkBtnSkipLoop. When I started adding the extra features within the BtnMenuAction block inside that loop I started to get unpredicatable behaviour and some program crashing. It didn’t like jumping out of a loop when inside a fairly complex nested structure inside that loop. Instead I inserted the simpler bkButtonLoop, and I controlled the operation and interaction with the Recording and Note generation loops using the EnableRecBtn logic flag variable. Whilst in any part of the Menu System the motor arm note generation and the recording of notes is disabled. If you need to exit the Menu without taking any action you can use the M button without holding down the Note Record Push Button. You can as before stop tune playback by shading the Ultrasonic or Infra-Red sensor depending on which model you are using. The only other part of the menu system that required alteration was to provide a means to exit the File Load or Save sub-menu without taking any action. This was done by employing the brick Left button which was not otherwise used.

Finally I modified the documentation to take account of changed Menu screens, and updated the program description text to accommodate the changes made. I also reduced the size of the initial display screen to accommodate smaller laptop screens. (I use a large iMac screen). I also added a small video showing the EV3COMPOS3R playing back a tune. You can find this on the Project Properties page.

The Retail Set Project Properties pageRETIIPROP

The Education Set Project Properties pageEDIIPROP

I have considered and experimented with adding further editing features to the program, but it greatly increases the complexity of the program, and the complexity for the user with multiple menus to achieve the desired effects, and I have decided it is not effective to go further. It is in fact fairly straightforward to do some editing manually by transferring the tune to your PC and using a suitable text editor. Note although it says .rtf the file is just pure text, and you should use a text editor like notepad and NOT a word processor. I use TextWrangler on my Mac. Also make sure that the text editor saves with CR/LF at the end of lines and not the more usual LF used in Linux. The reason for using .rtf is that this works for Mac downloads, whilst .txt cannot be downloaded with the EV3 software interface on a Mac.
The editing I have done is to copy and paste repeated sections of a long tune rather than entering them twice with the motors. Also, a couple of pieces required transposition of the music, in one case to fit the note range on the brick, and in the other to transpose the Trumpet part in Bach’s 2nd Brandenberg last movement. It was written in C in the score but needed to sound up a fifth. To transpose I copy the tune to a spreadsheet and use a formula to add the offset to each note, having entered it at the pitch shown in the score. You can also of course adjust wrongly entered notes either in pitch or duration. Just remember to adjust the note count at the beginning of the piece. It should equal the number of lines in the file minus 1 all divided by 2.

The new versions of the project can be downloaded below:

Retail Set project for EV3COMPOS3R II

Education+plus Extension Set project for EV3COMPOS3R II

Download of 3 packs of 10 tunes for either version of the project here with instructions for use

I hope to add further videos of the new version to YouTube soon

 

EV3COMPOS3R – a project to compose your own tunes

VERSION II is now published. The article here is instructive to read, but you are are better downloading the project files for version II from  a later post or
from EV3COMPOS3R II DOWNLOAD LINKS page

EV3COMPOS3R is a major project for Lego EV3. I have designed two versions, one of which can be built with the Retail 31313 set, and the other with a combination of the Education Core Set 45544 together with the Education Expansion Set 45560. In each case a project file is available containing full constructional details and the programs required.

EV3CPMPOS3R version for the Retail 31313 set

EV3COMPOS3R version for the Retail 31313 set

EV3COMPOS3R version for the Education 456544 and 45560 sets combined

EV3COMPOS3R version for the Education 45544 and 45560 sets combined

The project uses a total of 10 input devices! The position sensors on two motors are used to adjust the pitch and duration of the notes which will make up the tune, a push button is used to record the selected notes, an Infra-Red or Ultrasonic Sensor is used to select a menu for choosing the program options, the five buttons at the centre of the EV3 brick are used for multiple functions to choose the operations required, and a colour sensor (or a second push button sensor) is used to “nudge” the motor selecting the note pitch for fine adjustment.

The model consists of a framework to support the two motors and the sensors, and the output of the model is a tune which is stored in memory, and which can be fed to the sound chip on the EV3 brick. Facilities are also built in to allow up to 10 tunes to be saved to data files stored on the EV3 brick, which can also be uploaded to a PC if required.
One rotation of the left hand pitch motor controls the selection of the note pitch over a range of 3 octaves from C4 through C#4, D4, D#4…… up to C7, giving a total of 37 discrete notes.
One rotation of the right hand duration motor controls the selection of 16 different note durations ranging from 1 (semi-quaver), 2 (quaver), 3 (dotted quaver), 4 (crotchet) …. up to 16 (breve). Note durations that don’t have a simple musical name are signified by the duration in brackets, thus (5), (9), (10), (11), (13) and (15).

Because Lego has no error checking available if you try and read from a non-existent data file on the brick, a second program called initfiles is supplied the purpose of which is to write 10 empty data files to the brick before the main program called 002 is used.

Rests can be incorporated into a tune by selecting a note duration and holding down the DOWN button on the EV3 Brick while the note record push button is depressed.

Functions to delete the last recorded note, to clear the whole tune currently in memory, to Save or Load a tune to or from one of the 10 data files on the disk and to Playback the tune currently in memory are chosen from a menu which is selected by shading the Infra-Red or Ultrasonic-Sensor depending on the version being used. Two sub-menus allow for the selection of the file number to be used (1-10) and the selection of one of four preset playback tempo. To aid file selection, the tune length currently stored in each location is displayed when a file is selected.

The “nudge” facility previously referred to was added to make it easier to accurately select a note pitch, as the motor is a little “lumpy” to turn, and it is not always easy to select the correct position. On the 31313 version a red flap is rotated in front of the colour sensor, where it is detected, and the motor is switched on to rotate a small number of degrees. The same facility is added to the 45544 version using a push button to initiate the movement. If you rotate the motor manually to just below the pitch you require, you can then easily “nudge” the motor to the right position.

The program is quite complex. It employs 24 MyBlocks together with the two programs 002 and initfiles already referred to. The main program consists of five parts.
First an initialisation section bkInitialise displays some welcome screens, calibrates the two motor positions, and sets up one or two arrays and variables used by the program. Then four parallel processes are started, each consisting of an endless loop.

The first bkMPLoop (motor position loop) programs the two motors to produce integer numbers from 0 to 36 and from 1 to 16 to act as indexes for the pitch and duration values as they are rotated through just less than one revolution. Lookup arrays convert the pitch index values into the names of the notes and the frequencies of the notes which can in turn be displayed on the screen and fed to the speaker module. A lookup array is likewise used to display the duration names on the screen, and a divisor variable is used to adjust the tempo and produce the actual duration times fed to the speaker module.

The second process bkRecordLoop is used to record the selected pitch and duration index values each time the record button is pushed and store them in the successive elements of two arrays called tunenote and duration.

The third process bkBtnSkipLoop is the most complex, and deals with the various menu options for note deletion, loading and saving tunes to data files, clearing the current tune in memory and playing back the tune in memory. The heart of this section is a five way switch.

Further complexity is added to the first three parallel section by a variety of variable flags, which allow them to interact. Thus selecting a new note can exit the menu section (although this is inhibited whilst a tune is being played), and note recording is inhibited whilst a menu function is active. Also a flag allows the Infra-Red or Ultrasonic-Sensor to interrupt playback if you don’t want to listen to a tune in its entirety.

The fifth parallel process nudgemotorA contains the code to rotate the note pitch motor in small increments each time the relevant sensor is activated.

The program runs until it is stopped by pushing the stop button on the EV3 brick.

A short video of the project is here, and you can listen to one of the pieces on this link.

Better version of the video on youtube here

Downloads:
The retail version 31313 project file
The education version 45544 plus 45560 project file
A zip file of 10 tunes which you can download to the project folder on the EV3 brick

I hope you enjoy using this project. I welcome feed back comments!

 

Modified Lego Colour Sorter

I recently acquired the Educational Version of the Lego EV3 set together with the Expansion set, which enabled me to try out the models associated with these sets. One of the first ones I built was the Colour Sorter (I don’t like the american spelling Color!) This works well, but I thought the model could be improved. First you have to manually scan all the colour pieces as they are loaded onto the delivery chute, and also after each coloured brick is delivered the moving chute assembly returns to the zero position before the next brick is processed, which is a little inefficient in time.

Colour Sorter

The two changes I made, were first to move the colour sensor from the EV3 brick to the shute assembly so that the bricks were scanned just before each one was delivered, obviating the need for them to be scanned manually. Secondly, I altered the algorithm of the program, so that the chute records where it is and calculates where it has to move to before delivering the next brick. This makes the whole process a bit quicker and more efficient, although it relies on dead reckoning after the initial calibration of the chute position.

I have produced a project file with build details for the modified model, which should be read in conjunction with the original build instructions. The file also contains the modified program with a full description of its operation and a short video of the model in operation which is linked here also.
I hope you enjoy building it!