November 22

Nov 22, 2021 02:48AM

Bluetooth.

After MANY MANY long hours of trying to figure out bluetooth, I wwas ecstatic to finally have been able to connect the nano and parse the data properly. This is all thanks to Professor Scott’s help. Though the code he sent did not wwork for me (lots of errors and there were parts I hadn’t fully comprehended), I learned a few more things about data types (Endianness and some functions) and p5BLE data parsing, which allowed me to modify the BLE Read function in my code to read the incoming data as a float32 datatype.

After I got it sending one characteristic (acceleration x) over bluetooth, I worked on sending multiple pieces of data (acceleration xyz and gyroscope xyz). While Prof Scott used arrays, I failed to do so and thus ended up resulting in sending over each piece of data as it’s own characteristic. I initially planned on utilizieng two separate services (accelerometer service, gyroscope service) but realized it would be complicated. I noticed too that Prof Scott used only a single service (IMU Service). This made me realize that nesting all the pieces of data under the IMUService umbrella would make more sense.

literal tears of joy

I also tried it using a powerbank

Troubleshooting: Passing Multiple Pieces of Data.

I initially had encountered a barrier in figuring out what to do next since I needed to pass more than just one piece of data. Since I couldn’t figure out passing characteristics in arrays, I had to figure out a workaround. I needed to let the program know when it has been passed all the data for one set; otherwise it won’t know which piece to assign to the corresponding variables. I thought of a simpler solution that would require modifying and overriding a p5BLE function, but I was unable to figure out how to do that. In the process, however, I became more familiar with looking at github source code to understand the library better.

After a while, I realized I could create a new array in p5 that would store the values. This way, I could use array.length() to determine the size of the array which then determines whether or not it has gathered all the data.

Example: 6 pieces of data to be gathered. If array.length() == 6; then that must mean all data has been gathered.

Once this data has been gathered, I assign them to the apporopriate variables and clear the array to get it ready for the next set of data.

            function gotValue(error, value) {
            if (imuvalues.length < NUM_VALS) {
                imuvalues.push(value);
            }
            if (imuvalues.length == NUM_VALS && next == true) {
                //assign values if set is complete
                ax = imuvalues[0];
                ay = imuvalues[1];
                az = imuvalues[2];
                gx = imuvalues[3];
                gy = imuvalues[4];
                gz = imuvalues[5];
                roll = imuvalues[6];
                pitch = imuvalues[7];
                yaw = imuvalues[8];
                console.log("change")
                
                //clear array when values are assigned
                imuvalues = [];
                for (let i = 0; i < accelCharacteristic.length; i++) {
                    //call read function again
                    accelBLE.read(accelCharacteristic[i], 'float32', gotValue);
                }
            }

Madgwick

Professor Scott told me about this library that analyzed acceleration and gyroscope data and translated this into roll, pitch, and yaw/heading. It was fairly simple to utilize the library so I did that and added each of these variables as characteristics to be sent via bluetooth.

Tone.js

I figured that since I had all the data passing and bluetooth done, my next step was to figure out how to play the sound. This led me to explore more Tone.js and expand my knowledge of how to use the library better. I am in the process of doing so but have already discovered a few things that have allowed me to think of new ideas to explore the creation of sound.

Since I’ve already tried having a single movememnt produce a fixed length sound, this time, I decided to try to see how it would be if there were a continuous loop where movement changed the notes being played.

I encountered trouble due to the nature of loops. I did not find code to stop the loop for tone js and since it keeps going, different loops start playing over each other. I am still trying to figure out a way to make it so that each loop is distinct and only one is playing for the entire time.

Apart from this I also want to test out how I could modify what I had for my midterm demo to make it so that instead of having a fixed length note playing, I am able to have the note play for the duration of the movement.

I will continue experimenting with these two “modes” and see what else comes up and how I will pivot my way into something manageable but good. This means that the agenda for the coming weeks will be to explore more of web audio and ideate a physical means of interacticng with the device.

Link to p5 sketch experimenting tone sequences

upon testing with my accountability group, they mentioned that the first version was better (controlling one sound at a time)>

Misc: Power Supply

As I got excited about bluetooth working, I decided I’d plug the Nano into my powerbank and see the real magic happen (where the nano isn’t connected to my laptop via wire – I know I dont have code in place for serial communication but seeing the wire connect the devices makes me feel like that is the case).

Once I got it plugged in, I noticed that the powerbank would stop powering the nano after a bit. I figured it could be due to how little power the nano draws. Given this, I will have to figure out how to make powerbanks work, or figure out other alternatives to power the nano. The latter is preferred since I believe it may be possible to do so with a device with a power source that is smaller in size.