Category Archives: Physical Computing

Physical Computing classwork

PComp Week 8: SPI and I2C Labs

SPI Lab: Digital Potentiometer

I got the code and physical aspects setup but there was no change in the ton volume. I was expecting some range but there was nothing.

I did notice a discrepancy within the instructions for the physical set. In the drawing, the negative lead of the speaker is connected to the 100 ohm resister then to the digital pot but the text accompanying the diagrams contradicts that. I did try both and the results were the same. A tone was produced with no column variation.
SPI Tone Breadboard Setup 1SPI Tone Breadboard Setup 2

I2C Lab: APDS-9960 RGB and Gesture Sensor

First tried code from the lab but received errors that the APDS was undefined. I made sure to use the Arduino library but could not figure out how to rectify this.  I then added the Wire.h library which took care of that error.  Then, I received the following error. 

i2c error Arduino screenshot

I was thinking maybe the solder on the headers was maybe an issue so I tried tow examples from SparkFun library.

1 – Gesture Test
I was able to get the breadboard setup properly but did not get any readings on the serial monitor.

2 – ColorSensor
This test was successful. See video below of serial monitor output.

3 – Proximity Sensor
Was able to get this working within the serial monitor

The only quesiton  I have are why wont the other examples work for this sensor?

PComp Week 7: Project 2 – Game Controller Preliminary Documentation

For the 2nd project, I have decided to create a game controller with corresponding game.  The controller will be spherical with 2 force sense resistors (FSR) and a push button.  The object of the game will be to get a ball into a box.  The FSRs will control the x and y of the ball.  Once the ball is in the box, the ball will shrink and/or disappear as the box will turn red.  The button will bring a new ball into play as well as a new box.  The ball will start in the same location but the new box will be in a different location. 

The controller will have a hard inside with a foam covering and will fit in the palm of the user’s hand.  Below are my preliminary sketches followed by the breadboard set up for the controller:

Proj 2 NotesProj 2 Controller Design 2

Proj 2 Breadboard

It would be great to be able to have different size balls created each time that have to make it into specific boxes in order for box to close off.  This will depend on my coding skills but I am up to the challenge.  If I can add additional features to the controller I would like to do that as well.

I will be using the Arduino code from the Two-way Serial Comm Lab as a template to build off of.   So far, I have the following coded in P5.js:

Pressing the mouse mimics the effect of pressing the button on the controller.  I need to investigate further working with the objects and arrays in order to keep the sketch from slowing down.

Here is a demo of the sketch from the Two-way Serial Comm Lab using 2 FSR’s to control the ball. 

 

My next steps are 1) get the code squared away, 2) test out/mock up housing for controller, and 3) investigate materials for final controller. 

PComp WK 7: Two-Way (Duplex) Serial Comm Lab

Lab: Two-Way (Duplex) Serial Communication Using An Arduino and P5.js

Video: what is char and why is it used here?  This is a clip from Tom’s video Serial 6: Better Processing.

Char Image

Setup board with Force Seeing Resistor, potentiometer and bush button.

Breadboard Setup

Part A:
Ran program with just serial monitor and got the 3 numbers separated with ‘,’.

Part B: p5.js
Since I was not using the accelerometer in the Nano, I needed to change the values in serialEvent() so that the value ranges were applicable to the FSR and the potentiometer.

Receive Data in P5.js

 

Flow Control: Call and Response

The only challenge I had with this was getting the sketch to run.  I needed to close all the open post (P5.js and P5 Serial Control) then upload the sketch to the Nano without testing the call and response within the serial monitor.  Once that was done, I could open the port within the P5 Serial Control app then run the sketch in P5.js.

The sketch was smoother than the first because of the handshaking. 

 

Question:

Why does the last sketch not work after the P5.js sketch is stopped then restarted?  In order to get it to work again I have to close out of the serial control as well as uploading the Arduino sketch again.  Then I reconnect the Serial Control and restart the sketch.

PComp Week 6: Asynchronous Serial Comm. (P5.js Input/Output)

Lab 1: Intro to Asynchronous Serial Communications

 Overall. no issues working with Arduino although more practice and experimentation will be beneficial to understanding the concepts from this and the following labs.  I did, however, run into an issue getting the code to work for reading the Nano’s onboard accelerometer instead of using an external one.  The code provided stated the following:

accelerometer error

 I do nMeed more practice with understanding handshake and call and response.

Lab 2: Serial Input to P5.js

Tried again with a fresh mind and was able to get it working.
Insert video 1A (Fig. 13 related video)

After Fig. 13, within the “What’s Happening Here” section, the text states:
“You may be wondering why you’re mapping the sensor value or dividing it by 4 in the Arduino sketch above. That’s because in order to send the sensor value as a single byte, it must be between 0 and 255, or no more than 28 bits.”

Where are we dividing the sensor value by 4?

ANSWER: within map, we are mapping the sensor value from 0-1023 to 0-255. 255 is right 1/4th of 1023.

2B: Graph

Tried adding delay(100) to the loop. Which loop?
Tried adding within draw, received error noting delay is not defined.
Tried adding to graphData() after if statement, same response.
Where do I add the delay to effect the loop?

ANSWER: Add to the Arduino sketch not p5.js

2C: ASCII
Added println(inData) and received error: printlin is not defined then my computer started overheating and the browser was working hard (spinning). Had to restart browser.

Changed println(inData) to console.log(inData) and it worked. There was a definite delay though.

Screen Recording 2020-10-20 at 10.34.55 AM

Lab 3: Serial Input to P5.js

3A: LED
I was able to get the LED to respond to the movement of the mouse as well as if I typed 0 though 9. The LED changed it’s brightness as expected.

I did have to edit the code in function keyPressed(){…} as the && signs were showing up as && which caused an error.

Also tried the speaker for this lab but used a 220Ω resistor instead of the 100Ω requested in the setup.

3B: ASCII encoded numeric string
Tried this part with the speaker setup and was able to get it to work. H produced a tone and L ended the tone.

Running the code through p5.js using H and L worked! 

3C: Processing ASCII-Encoded Strings With Arduino

I don’t really understand this part. I was able to add numeric strings into the serial monitor and the speaker beeped a few times before it stopped taking input/making sound.

I am not sure exactly what is happening with his lab.

I would like to get further examples of using Table 1. Serial Communication: p5.js to Arduino (below) as I think it might help to clarify any confusion. 

chart

PComp: Project 1 – Social Distancing Crown

Yona Ngo, Yonatan Rozin and I were paired together for this project and decided to create what came to be called the Social Distancing Crown.  For more info on our initial planning, please check out my last PComp post here.  You can also see Yona and Yony’s blog post here: Yona, Yony.  (ATTACH LINKED POSTS).

Below is a breakdown of the project production by day. 

Day 1:

Yona, Yony and I met on the ITP floor in Brooklyn to parse out each item.  Once we figured out the individual components, we will meet again to combine them into one piece.
Yona – speaker and ultrasonic ranger
Yony – servo moto
Daniel – LEDs

Yona found several LED NeoPixel strands on the free shelf so we decided to use those.  I started by researching the specific strands and was able to find one of the strands info as it had the manufacturer’s name printed on it – Alitove.  I was also able to find a guide which helped get me started.  I learned that each NeoPixel draws 50mA of power and needs 5V 2A of power. 

As a starting point, I used this drawing for the circuit as well as Adafruits NeoPixel guide:

Tried originally tried utilizing the code from randomnerdtutorials.com guide but that was not working for so I switch to Adafruit’s learning page from that point on.Nano Schematic Initial Nano Circuit

Day 2:

I started the day out trying to figure out the following questions:
Questions:

  • Would I need a 3.3V Regulator if I wanted to power the Nano 33 IoT from the 9V battery as well?
    • Answer: Yes, I would need a 3.3V regulator to power the Nano but I would also need to convert the 9V to 5V in order to power the NeoPixels. 
  • Do I need a logic level shifter per Adafruit (https://www.adafruit.com/product/2488) in order to use the Nano 33 IoT?
    • Answer: Yes, but did I want to have to get one?  No.
  • Library: Would we want to use the Adaruit TiCoServo Library since we will be using a servo in the same sketch? 
    • Answer: Yes and No.  (more to come on this later).

I attempted to configure the circuit using the Nano 33 IoT with little success.  In order to I would need a logic level shifter for the NeoPixels and the Nano to be able to speak to each other as the NeoPixels need a 5V current for their coding as well as for power.  I decided to switch to using an Adafruit Metro.  The Arduino Nano 33 IoT runs on 3.3V and offers ways to run components off of 5V but it was the least complicated to to switch microcontrollers. Adafruit’s guide does mention that you would be able to run a short length of NeoPixels using 3.3V but it would only get more complicated one we added all the components. 

Day 3:

I started the day by meeting with our professor, Dave Rios to discuss my progress with the NeoPixels.   Dave suggested the following:

  • Continue with the Metro or Uno since we were able to get them working during the meeting.
  • Our biggest challenge will be in regards to powering the entire circuit once all the components are added. 
  • Get the components added one at a time instead of all together.

Later that day, I tested out setting the NeoPixel strips to a single color using Adafruit’s guide.   I ran into one chaleneg with the colding: how do I use Color( )? 

While testing out the coding from Adafruit’s NeoPixel library, I was only able to get color() to show various bightnesses of blue but was unable to get a different color.  Adafruit NeoPixel Library Example CodeBlue NeoPixelsIt took me a bit but I was able to find the following code which showed me how to define then update the colors of the NeoPixels:

Change ColorCode MagentaMagenta NeoPixelSingle NeoPixel Schematic

Now that I was able to control the color of one NeoPixel strand, I wanted to test out how to have 2 NeoPixel strands on one board. I used the following code but was unsuccessful in having the black NeoPixel strip as Green and the white NeoPixel strip as Red.

Double NeoPixel Code NeoPixel Strands Double NeoPixel Schematic Breadboard View

Day 4:

I meet with ITP resident Arnab Chakravarty to go over my questions with the Adafruit library.

Adafruit uses the terms #define followed by LED_PIN 6 to establish that pin 6 will host the output.  Per Arnab, this is the same as assigning using PinMode.  Arnab was able able to walk me through utilizing the library and working with the two NeoPixel Strips.

Day 5:

Meet with Yona on the floor.

Added the ultrasonic ranger (w/o the speaker) to the NeoPixle circuit.
⁃ Added 9V battery with 5V regulator for Ultrasonic ranger
⁃ Updated code from earlier as I forgot to declare the NeoPixel strip object.

Test 1:
Taking into account changed items listed above.  I was able to get the NeoPixel strip to start as green then turn red as I moved my hand closer to the ultrasonic ranger.  I was not able to get the strip to turn back to green once out of range, however.

Test 2:
Changed (line 49)
else {
setNeoPixelToGreen(); //Sent NeoPixel to Green
}

to

else if (distance > 10 && previousValue > 10) {
setNeoPixelToGreen(); //Sent NeoPixel to Green
}

This was an attempt to get the NeoPixel to change back to green when distance is greater than 10 and the previousVaule greater than 10.Ranger UltraSonic Ranger and NeoPixel Circuit

Test 3: Running sonic ranger off battery.  The ranger was not reading properly whilte the lights working momentarily.

Test 4: Running NeoPixels off 9V battery.  This was unsuccessful as the NeoPixels did not light up.  (I realize on Day 6 that I was using a 3.3V regulator instead of the 5V regulator I needed for this to work). 

Yona and I were finally successful in getting the sensor, speaker and NeoPixels to work together!Circuit minus ServoCircuit Schematic minus Servo

Next step was to build the housing for the components.  Once built, I tested the wiring to make sure nothing came undone during this step.  It was all working and ready for the servo motor. 

 Housing Step 1 PatternInside of Crown HousingOutside view without the servoInside view 2

Day 6:
Yona, Yony and I met at the ITP floor to complete the circuit by adding the servo code to the overall code. 

We considered adding an Op Amp to the circuit so that the voice would be louder but, after reviewing the datasheet of the component, decided that this would best be left to another time.  We were not sure even where to begin with working it into the circuit as the datasheet was not clear enough.  Dave Rios suggest using fig. 22 on page 25 of the TL072P’s datasheet.  Unfortunately, we were not able to fully decipher the schematic in time to implement into the finished project.  If we pursue refining this project, we will invest in finding an amp to bring out the voice.  

Test 1: servo moved at start but did not move again while the other components acted as desired  Tested adding 9V battery for servo, unsuccessfully.

Test 2:
Realized that I had been using a 3.3v regulator in the circuit with the batter so I switched instead to a 5V regulator.   Unfortunately, nothing still.

Test 3:
Checked the power for all by unplugging speaker and NeoPixels to test if the servo moves more than one. It did not.Complete Circuit Ready for Final HousingFinal Schematic

Final Front View Final Side View Final Backview

 

Conclusion:
We were unable to figure out why the servo only worked once in combination with the speaker and NeoPixels.  We were however able to create a piece that works once! 

 

We recorded 2 videos: (1) just the servo running its original program by Yony and (2) the final piece with the servo only running that initial time.

Questions for the next build:

  • How do we implement the amp into the circuit?
  • How do we get the lights to change, the voice to speak and the finger to wag without a delay?
  • How do we properly power the entire circuit (this might have been the issue with the lag and the inability of the servo to function)?
  • Besides drawing in Illustrator or photoshop, how can I improve on my schematic diagrams? 

Additional Component Datasheets and Guides:
Sensor datasheet: https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf
Servo datasheet: https://cdn-learn.adafruit.com/downloads/pdf/analog-feedback-servos.pdf
Nano 33 IoT:
https://itp.nyu.edu/physcomp/introduction-to-the-nano-33-iot/
NeoPixel Strands: https://www.alitove.net/product/ws2812b-300bk-np/