Bake Mate - Pi Chef Blog #3 - RPi3 setup & recipe JSON format
Setting up the Raspberry Pi 3:
This part is easy:
- Insert the microSD card that's been preinstalled with NOOBS
- Plug in a USB mouse, USB keyboard and connect the Pi to a display via HDMI.
- Connect the Power supply to the Raspberry Pi 3!
The Raspberry Pi 3 will boot NOOBS. I entered the credentials of my WiFi network, and NOOBS started the process of downloading Raspbian (which is around 3GB).
For some reason, the RPi hung a couple of times in the middle, which meant that I needed to restart the entire process.
Once it got done, the next step was to setup the 4DPi-24-HAT.
This requires a few extra steps because this display HAT doesn't use the RPi's native display connector, but relies instead on a SPI connection (via the 40 pin GPIO connector).
Due to this, it requires a kernel patch (which is provided by the vendor).
I followed the instructions on the website because they seemed to be newer that the setup guide booklet that shipped with the display.
I plugged in the display, and nothing! After a little reading, it turns out you need to move the jumper that controls display PWM from the default shipping position of "PWM" to "ON".
There is a method of calibrating the touchscreen (which is required based on my experience with the display, but I haven't yet got down to doing that.
The display works well, but Raspbian isn't designed with such a low resolution in mind, which is why a lot simply gets displayed off-screen.
The user manual has a few tips on how to make it a little more usable, which involves decreasing the size of icons and fonts. However, most programs run at the native resolution, which makes them difficult to use since the "OK", "Apply" & "Cancel" buttons remain offscreen.
Keeping this in mind, I designed my Python GUI appropriately: the window resolution is capped to the resolution of the display:
I've been working on the GUI, and here are a few of the elements I've finished so far:
Recipe JSON format:
I designed the format based on several requirements; each recipe should have:
- A name
- A description
- No. of servings
- Cooking time
- no. of Steps (initially added to make parsing easier, but I think I could get away without using this)
- An array containing all the steps, where each step contains:
- Sequence number
- Text instruction (description)
- Instruction type (different types include:)
- A simple 'do': This type won't contain ingredient amounts because it is a simple instruction like "Stir" or "Melt chocolate"
- Add measureable: This type will contain the ingredient, the amount and the unit. An instruction with this type of tag will cause the program to enable the weighing scale.
- Add immeasurable: This is for ingredients that are too small to measure, or have no unit in general: a pinch of salt, a drop of flavouring etc. I've added this because they count as instructions and will need to be present in the final ingredient checklist.
- Bake: This type will trigger the method that measures oven temperature and sets the timer.
- Ingredient (name)
- Unit of the ingredient: This will make it easier to automatically convert units
- Value of the amount of the ingredient
For example,
{ "name": "Easy Chocolate Fudge", "Description": "Quick & easy one bowl chocolate fudge", "Servings": "48", "CookTime": "3 hours", "nSteps": "6", "Steps":[ { "num": "1", "txt": "Line a 8x8 dish with aluminum foil ", "type": "do", "ingr": "NA", "ingrUnit": "NA", "ingrValue": "0" }, { "num": "2", "txt": "Add chopped chocolate", "type": "addm", "ingr": "Chocolate", "ingrUnit": "gm", "ingrValue": "450" }, { "num": "3", "txt": "Add a tin of condensed milk", "type": "addm", "ingr": "Condensed Milk", "ingrUnit": "oz", "ingrValue": "14" }, { "num": "4", "txt": "Heat till it melts", "type": "do", "ingr": "NA", "ingrUnit": "NA", "ingrValue": "0" }, { "num": "5", "txt": "Add Vanilla", "type": "addnm", "ingr": "Vanilla Essence", "ingrUnit": "NA", "ingrValue": "0" }, { "num": "6", "txt": "Add Walnuts", "type": "addm", "ingr": "Walnuts", "ingrUnit": "gm", "ingrValue": "180" } ] }
The JSON format might change with time as I go over more recipes and encounter a step that cannot be covered using the existing format.
Status Update:
I didn't get any time to work on it during the week, but I did work on a few GUI elements today. I figured out how to populate the list of recipes by scanning JSON files in a directory and parsing the recipe name from each file.
I also did a little work on cleaning up some code and modularizing it:
When I started off, I was working on programs for parsing recipes and the the main GUI in parallel. I'm reaching the point where everything needs to be integrated, so I though that it was time that I tidy up my code so that it easier to integrate.
While this program isn't big by any means, I can tell that it will become too difficult to manage in a week or two if it's not sorted our and structured well.
I initially planned on learning advanced Python & tkinter before applying it, but have now decided to take a different approach: identify a problem, and figure out the solution.
Method 1 was ideal, but it takes too much time because I realised that I tend to get stuck reading books and tutorials instead of working on a set of problems. Method 2 is definitely more time-efficient.
The shipment containing the load cell for the weighing scale got delayed, but should get here sometime early next week.
Next on the list:
- Sort out and clean up the code: create well defined functions and create modules that are easy to use.
- Now that the main parts of the program are done, it's time to start working on the screens for the steps. I'll need to be careful because there are four types (depending on the step type), and they will need to be designed so that they're easy to reuse.
- I'll also need to figure out a robust way of keeping track of the current step: it is very important to ensure that the application doesn't glitch, as suddenly losing your current progress in the middle of a recipe won't be fun.
- I'll start work on the weighing scale and the code when the load cell gets here.
Top Comments