Blog 4 - Analog Out

 Iteration 4 - Analog In/Analog Out (Jay Langford)

March 14, 2025

IoT Apps Iteration 4 - Micro:bit Spotify Integration (Analog In/Analog Out)

For this iteration, our task was to develop a complete application demonstrating both analog input and output using a transport layer to send data between the cloud and a micro:bit. Working as a team with Daniel Lawton, we created a Spotify integration that allows users to control music playback (analog in) and view track information on the micro:bit's LED display (analog out).

Project Overview

During the Monday class on February 24, 2025, our lecturer Jason tasked us with creating a full AI/AO application using cloud messaging protocols. After brainstorming together, I proposed the idea of creating a micro:bit MP3 player that would allow users to skip tracks and display current song information. We divided the work based on our strengths - I took responsibility for the Analog Input component while Daniel focused on the Analog Output aspects.

Analog Input Implementation

I led the development of the Analog Input section, which involved configuring the micro:bit to send commands to Spotify when buttons were pressed. The implementation included:

Wi-Fi Configuration: Setting up the micro:bit to connect to our classroom network:
ss

IFTTT Integration: Configuring the webhook to call Spotify's API with the "skip track" command when Button A was pressed:
ss

Spotify API Research: Finding and implementing the Spotipy Python library to access Spotify's API, creating a developer app to obtain API and secret keys.

I encountered some challenges with certain Spotify API calls through IFTTT. When attempting to use different API calls to play songs, the requests wouldn't work properly. After troubleshooting, I discovered that the "next_track" command needed to be explicitly specified in the webhook trigger. We decided to focus on perfecting the working skip track functionality rather than spending more time debugging other commands.

Analog Output Implementation

IFTTT Limitations: Daniel discovered difficulties integrating IFTTT with the micro:bit to receive values. While triggering the IFTTT applet with a webhook through makecode worked, receiving a value from the IFTTT applet using GET instead of POST caused issues.

Solution Development: To overcome these challenges, Daniel pivoted to using a local server approach. He implemented a Flask server that could be used to send HTTP requests between the micro:bit and Spotify's API.

Data Display: Daniel configured the micro:bit to display the currently playing track information on the LED display when Button B was pressed, implementing the HTTP GET request functionality:
ss

I was impressed by Daniel's problem-solving approach and his ability to pivot when the initial method wasn't working as expected.

Integration and Teamwork

By the end of the first week, I had successfully implemented the Analog Input component for skipping tracks. Daniel then continued working on the Analog Output side to display the current track information.

Our regular communication and collaboration were essential to the project's success. When Daniel encountered issues with the IoT extension in MakeCode, we discussed alternatives and decided together to switch to direct HTTP requests instead of relying solely on IFTTT, as they offered more flexibility for both POST and GET operations.

The integration between our components worked as follows:

- My component (Analog Input): User presses Button A, which triggers an IFTTT webhook to skip to the next track on Spotify

- Daniel's component (Analog Output): User presses Button B, which makes an HTTP GET request to the Flask server, retrieving and displaying the current track information

Technical Implementation

The complete technical implementation involved several integrated systems:

Spotify API Access: Using the Spotipy library with proper authentication:
ss

Flask Server (Daniel's implementation): Creating endpoints for the micro:bit to access:
ss

Micro:bit Configuration: Setting up both the input (Button A for skipping tracks) and output (Button B for displaying track information) on the same device.

One challenge we faced was that when having both AI/AO on the same micro:bit board, the AI part with IFTTT would sometimes conflict with the HTTP requests. We needed to ensure that both components could coexist without interference.

Reflection and Conclusion

This project provided valuable insights into IoT development and cloud integration. Working together as a team allowed us to overcome technical challenges that would have been difficult to solve individually.

Key Learnings:

  1. Transport Layer Integration: We gained practical experience in implementing a transport layer for bidirectional communication between cloud services and IoT devices. Understanding the limitations of various protocols (IFTTT, HTTP requests) was crucial for developing an effective solution.
  2. Problem-Solving Approach: When faced with technical challenges, our ability to pivot and find alternative solutions proved essential. Daniel's move from IFTTT to a Flask server for the Analog Output component demonstrated the importance of flexibility in IoT development.
  3. Full-Stack Development: The project required us to work across multiple layers - from the micro:bit code to server-side implementations and external API integrations. This comprehensive approach enhanced our understanding of full-stack IoT development.
  4. Real-World Application: Creating a practical use case that integrates with a popular service like Spotify made the project more engaging and demonstrated the real-world applicability of IoT concepts.

Future Improvements:

If we had more time, I would like to explore:

  • Implementing more commands beyond track skipping (play/pause, volume control)
  • Developing a more sophisticated display for track information, perhaps using external components
  • Creating a more robust error handling system for network connectivity issues
  • Exploring MQTT as an alternative to HTTP for more efficient communication

Overall, this Analog In/Analog Out project successfully demonstrated bidirectional communication between cloud services and IoT devices, showcasing both our individual technical skills and our ability to work as an effective team. The combination of my focus on API integration and control mechanisms with Daniel's expertise in server development and data display created a comprehensive solution that fulfilled all the project requirements.

Comments

Popular posts from this blog

Iteration 2 | Jack | HRV Micro:bit Research

Iteration 5.2 | Lock In | Jack

Week 1: HRV Review