Edd Mann Developer

Building a Secret Santa allocator and SMS sender using a Raspberry Pi Pico/MicroPython and SIM800L module

Over the past couple of years I have explored several different ways in which to solve the problem of allocating Secret Santa’s for members of my family. Having spent a couple of months recently interested in microcontrollers, I decided that this year I would send out automatically allocated Secret Santas via SMS using a Raspberry Pi Pico/MicroPython and SIM800L GSM module.

The build

The system I designed comprised of a display (that I had used in a previous project), the Raspberry Pi Pico and a SIM800L GSM module. Upon boot the system reads in the supplied participants.json file which contains the participants names and phone numbers. Once allocation commences all participants are assigned a Secret Santa, with the resulting allocation notifications being sent out via SMS. The display is used to report the current status throughout both the allocation and notification phases. The final solution can be found on GitHub, with additional usage instructions included.

The allocation process

I decided to use the same technique I had employed in a previous years solution to allocate the Secret Santas. This method applied a brute-force approach which uniformly shuffled the given participants into pairs, returning the allocations if all pairs met the desired criteria (i.e. not oneself or within an exclusion listing). Looking through the MicroPython documentation however, I noticed that no array shuffle functionality was present. As such, I opted to implement my own Fisher–Yates shuffle algorithm which performed these capabilities of which were lacking from the standard library. MicroPython does however provide some of the high-level Python constructs I have grown accustom to (such as zip and all) which produced a very succinct end solution.

Sending the SMS

The most interesting part of the entire project was exploring how you could send SMS using the Pico. The SIM800L module is a GSM cellular chip which communicates with the microcontroller via UART. I opted to build a small abstraction within MicroPython around communication with the SIM800L via AT commands. This abstraction handled the necessary initial configuration setup and connection to the mobile network provider. Further more, it encapsulated the behaviour required to send an SMS to a given phone number.

Conclusion

This was by-far my most enjoyable Secret Santa allocation system to design and build to date. Having the ability to begin the allocation process using a physical button, and subsequently see progress reported on the display was very pleasing. I really look forward to exploring other ways in which I can use mobile network communication within projects such as this in the time to come.