Inspiration

Don’t you just hate it when you are binging on Netflix’s latest season of Narcos and all the sudden you fall asleep and you have no idea where you left off or you rudely awaken by the loud volume of the TV. Don’t worry the Netflix socks will automatically will turn off the TV when you fall asleep allowing to stay asleep and save where you left off. To interact with it, we need to wear the socks. The certain place should help the device distinguish whether we are awake or sleeping. When the device believes we’ve dozed off, it will flash a LED to indicate to the user the TV is about to be turned off. If we still have no motion, it will send out a signal to turn off the TV.

Features

  • Command Line Interface for device testing.
  • Over the Air Firmware Update.
  • Remote Monitoring of accelerometer to detect motion.
  • Device Security with CRC32 checksum and signature.
  • Remotely turn off TV over the cloud.
  • Interaction with smart home system.

How we built it

High Level Design Diagram

Hardware

The ADXL345 was used to detect user's motion. It's a small, thin, low power, 3-axis MEMS accelerometer with high resolution measurement and digital output data accessible through I2C interface. It can measure static acceleration as well as dynamic acceleration resulting from motion. It's the perfect sensor for couch potato.

For actuator, we use an Infrared LED to turn off TV. In order to simulate this action, we install an Infrared Receiver on the other board, which will blink the user LED when it detects infrared signal.

Since both boards held the same components (emitter and receiver) and source code a jumper was implemented to dictate the which board was an emitter or receiver. This allowed us to push the same firmware update code and not have to worry about sending the correct update packets to the correct boards.

Software

  • NVM and external flash chip There're two storage place on our device: NVM of SAMD21 chip and the external flash chip AT25DF081A. We store the 1)firmware control information, 2)bootloader and 3)the current executing firmware in the NVM. Whenever we download a certified firmware, we will store it on the flash chip with the ping-pang style. The partition table of NVM and AT25DFX chip is as follows:

SAMD21 NVM 256KB

Index Address Name
1 0x00000 Bootloader
2 0x07F00 Boot Status
3 0x08000 Application Code
4 0x40000 End of memory

External FLASH 8MB

Index Address Name
1 0x000000 FW Slot#1 Data
2 0x040000 FW Slot#2 Data
3 0x7D0000 End of memory
  • Bootloader

For bootloader part, we first get the firmware control information from NVM. If the flag indicates that we need to update firmware, the bootloader will carry the latest downloaded firmware from external flash chip to the nvm. After this, it will turn of the update flag and jump to execute the firmware.

Bootloader Flow Chart

  • Firmware The firmware is responsible for downloading new version of code over the cloud, sensing user's motion and sending to the could, listening to command over the cloud, etc.

Firmware Flow Chart

Challenges we ran into

The most challenging aspect of the firmware is how to handle the http connection. For the firmware update, the code downloads the metadata and checks the firmware version first. If the firmware needs to be downloaded, a new http request is initiated and the new firmware is retrieved. However, the responses of two http requests will arrive randomly. If the last ACK of the first http request arrives in between the second request, the second one will stop downloading automatically. In order to solve this problem, we distinguish these two different requests by the data length being sent in the http response, and maintain status of http requests separately.

The second biggest challenge was how to calculate the checksum in order to confirm the firmware is not corrupt. The Atmel Studio Frameworks(ASF) provides a function, which calculates the checksum based on the data and its length. In order to get the same value as the ASF algorithm, a small executable program developed, which takes the firmware binary file and version number as input, and generates the metadata needed. This procedure ensures the metadata format is exactly the same each time, and the checksum is exactly the same as the one ASF algorithm would generate.

During the process of board bring up several hurdles were encountered. When inspecting the board we noticed several components were misplaced by the manufacturer. Additionally, when ensure proper voltage levels were present at different nodes throughout the board we noticed the reset line was consistently held low as this is an active low pin. This would make flashing new piece of code onto the microcontoller impossible. To mitigate this issue the VBAT pin was isolated by scrapping copper around the pin and creating an island. This allowed us to solder on a jump wire from 3.3 Volts to the reset line.

A second issue we encoutered is when we tried to view our command line interface for testing the software. In the board schematic an error was made where the TX and RX were tied to the FTDI chip TX and RX pins respectively. The FTDI chip requires the RX from the MCU to be tied to the TX for the FTDI chip and the same applies for the TX pin. During the schematic phase we placed a breakout pins for the TX and RX of the MCU for debugging purposes. This foresight allowed us to bypass the FTDI chip.

What we learned

  • Product design process.
  • Component selection based on aims, power consumption and budget.
  • Power management circuit.
  • Atmel Studio Framework.
  • Schematic and 4 layer PCB layout.
  • Debug with debugger.
  • I2C, SPI, UART protocol.
  • HTTP protocol.
  • MQTT protocol.
  • Prototype board bring up.

What's next for Couch Potato

Couch potato is a flexible IoT device, which can be expanded to new features! For example, it can cooperate with other IoT device to build a smart home system. If it detects the user has fallen asleep, it can communicate with other controller to generate a more comfortable sleeping environment for the user. For example, it can turn off the lights such as the Philips Hue by sending JSON objects through the cloud. Also it can activate a home security system for the night. In future, we will explore how Couch Potato can incorporate this features in a close loop control system. Since communication through IR was not 100% reliable we plan to use Netflix API from NodeRed for direct interaction with Netflix, allowing us to mitigate issues with direct line of sight between the IR emitter and receiver.

Built With

  • altium
  • asf
  • c
  • samd21
  • winc-1500
Share this project:

Updates