element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Pi Chef Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Pi Chef Design Challenge
  • More
  • Cancel
Pi Chef Design Challenge
Blog Bake Mate - Pi Chef Blog #10 - Bake Mate gets smarter
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: avnrdf
  • Date Created: 16 Mar 2018 9:34 AM Date Created
  • Views 777 views
  • Likes 6 likes
  • Comments 2 comments
  • pi_chef
  • bakemate
  • pi chef - bake mate
  • pi chef design challenge
  • pi chef
  • pi-chef
Related
Recommended

Bake Mate - Pi Chef Blog #10 - Bake Mate gets smarter

avnrdf
avnrdf
16 Mar 2018

Bake Mate - Pi Chef Blog #10 - Bake Mate gets smarter

 

In the last blog post Bake Mate - Pi Chef Blog #9 - Mixing hardware & software , I demoed Bake Mate in action. The project is now almost complete - the weighing scale and thermocouple have been integrated into the application & I'm now working on the finishing touches.

 

This blog post will cover what I've added since the last post. These include:

  • Automatic unit conversion for weights - oz & lb are automatically converted to gm. The 'addm' screen displays the weight in gm (I'm going to add oz & lb soon), and the weight of the ingredeint added at the current steps in percent and the progressbar.
  • Automatic unit conversion for volumes - cups and litres are converted to weights. The densities of commonly used ingredients like oil, water, milk, flour, butter and cocoa powder have been stored, which allows the application to convert the volumes to weights.
  • Automatic unit conversion for temperatures: GasMark and Fahrenheit get converted to C.
  • BakePage countdown timer

 

Automatic unit conversion for weights:

 

#read the value and unit of next ingredient
    #step ingr unit
    thisrecipe.cur_step_ingrUnit = (data["Steps"][(thisrecipe.cur_step)]["ingrUnit"])
    #step ingr value
    thisrecipe.cur_step_ingrValue = (data["Steps"][(thisrecipe.cur_step)]["ingrValue"])

if (thisrecipe.cur_step_ingrUnit=="lb"):
        print("Detected lb. converting to gm")
        thisrecipe.cur_step_ingrUnit = "gm"
        thisrecipe.cur_step_ingrValue = str(round(float(con.LbtoGm(int(thisrecipe.cur_step_ingrValue)

 

The first 2 statements parse data from the json file: the unit and value of the ingredient. If the unit is 'lb', it calls 'LbtoGm', which converts values from Lb to Gm.

'LbtoGm', along with all the other conversion formulae are defined in converter.py.

 

def LbtoGm(lb):
    return (lb*453.592)

Automatic unit conversion for volumes:

 

if (thisrecipe.cur_step_ingrUnit=="cups"):
        print("Detected lb. converting to gm")
        if (thisrecipe.cur_step_ingr=="Water"):
            thisrecipe.cur_step_ingrValue = str(round(float(con.CuptoML(int(thisrecipe.cur_step_ingrValue))*1.0)))
        if (thisrecipe.cur_step_ingr=="Milk"):
            thisrecipe.cur_step_ingrValue = str(round(float(con.CuptoML(int(thisrecipe.cur_step_ingrValue))*1.033)))
        if (thisrecipe.cur_step_ingr=="Oil"):
            thisrecipe.cur_step_ingrValue = str(round(float(con.CuptoML(int(thisrecipe.cur_step_ingrValue))*0.95)))

 

This section of the code detects the unit & if it is a volume (cup, liter etc), converts it to gm. The 'if' statements are used to detect the type of ingredient and if it's a commonly used one like water, milk, oil etc, it converts it weight be using the density (the values that it is multiplied by at the end of the statement).

 

If the density of the ingredient isn't known, Bake Mate doesn't convert volume into weight and displays the amount that needs to be added, without any modification. The user will need to measure out the volume and add it (like it was done in the old days - before the Bake Mate image)

 

def CuptoML(cup):
    return (cup*236)
def GallontoMl(gallon):
    return (gallon*3785)

 

CuptoML is defined in converter.py, with other conversion functions.

 

I'll be changing how density calculations & volume conversions are handled. The current method of 'if' statements is easy and quick to implement, but isn't easy to modify (when I need to add more densities) and it doesn't scale well.  I'll be defining a lookup table with ingredient densities, which will be referred to by the program. This makes everything 'neater' because it'll be easy to add densities without making modifications to the actual code.

 

Automatic unit conversion for temperatures:

 

thisrecipe.cur_step_bakeTemp = (data["Steps"][(thisrecipe.cur_step)]["bakeTemp"])
    thisrecipe.cur_step_bakeTempUnit = (data["Steps"][(thisrecipe.cur_step)]["bakeTempUnit"])
    if(thisrecipe.cur_step_bakeTempUnit == "GasMark"):
        #convert it to C - the real unit :)
        tempC = con.GasMarktoC(int(thisrecipe.cur_step_bakeTemp))
        thisrecipe.cur_step_bakeTemp = round(tempC,2)
        thisrecipe.cur_step_bakeTempUnit = "C"
    if(thisrecipe.cur_step_bakeTempUnit == "F"):
        #convert it to C - the real unit :)
        tempC = con.FtoC(int(thisrecipe.cur_step_bakeTemp))
        thisrecipe.cur_step_bakeTemp = round(tempC,2)
        thisrecipe.cur_step_bakeTempUnit = "C"

 

This parses the value and unit of the baking temperature and converts it to Centigrade. However, the Bake Page shows all 3 units - Centigrade, Fahrenheit and Gas Mark to make it convenient for the user.

 

BakePage countdown timer:

 

The editor on the e14 website is buggy for some reason, so I'm only posting the important code.

def startclk(self):
        self.runtimer = 1
        print ("start clock")
        print ("run timer idasds " + str(self.runtimer))


    def updatetxt(self):
        self.durVar.set(thisrecipe.cur_step_bakeTime+" minutes")
        self.tempVar.set(str(thisrecipe.cur_step_bakeTemp)+ " C")

        self.mins = thisrecipe.cur_step_bake_m
        self.hours = thisrecipe.cur_step_bake_s
        print("mins is " + str(thisrecipe.cur_step_bake_m))
       
            thisrecipe.cur_step_bake_s -=1
            
        if (thisrecipe.cur_step_bake_s == 0):
            thisrecipe.cur_step_bake_s = 60
            thisrecipe.cur_step_bake_m -=1
            if (thisrecipe.cur_step_bake_m ==0):
                thisrecipe.cur_step_bake_h -=1
                thisrecipe.cur_step_bake_m = 60
                  
        self.timeVar.set(str(math.floor(thisrecipe.cur_step_bake_h))+":"+str(thisrecipe.cur_step_bake_m)+":"+str(thisrecipe.cur_step_bake_s))

 

The startclk() function gets called when the 'Start' button the on BakePage is clicked. This sets the 'runtimer' variable to 1, which enables the count (there is an if statement that decrements the counter only if runtimer = 1). The countdown operations are calculated using the 'if' statements, which first decrements minutes when seconds hits zero. It also resets seconds back to 60 and decrements the hour count if minutes hits zero.

 

updatetxt() is called every second using the tkinter 'after' method:

self.after(self.TimerInterval,self.updatetxt)   
self.TimerInterval = 1000
        self.updatetxt()

The 'after' method calls the 'updatetxt; method after 1 second. The 'after' statement is in the updatetxt() method, so once it's called, it automatically calls itself every second. This method is also used for updating the GUI on pages where the values change (the weight in AddM and temperature & time in BakePage).

 

This code is in the module that parses data from the recipe json file:

 

thisrecipe.cur_step_bake_m = (int(thisrecipe.cur_step_bakeTime)%60)-1
    thisrecipe.cur_step_bake_h = (int(thisrecipe.cur_step_bakeTime)/60)
    thisrecipe.cur_step_bake_s = 60

I selected minutes as the unit for storing baking time in the json file, so I need to convert the minutes to hours, minutes and seconds to display the timer. The three lines of code do that.

image

 

For example, "bakeTime": "73" in the json file is 73 minutes, which needs to be displayed as 1 hour & 13 minutes.To find hours, I used the division operator, and to find minutes I used the modulus operator (which gives the remainder of a division operation) minus 1, because one minute gets converted to 60 seconds.

 

Next on the list:

 

With the 'smarts' added, Bake Mate is a step closer to being complete.

 

  • I've already done some work on the mobile notification system that generates alerts when the oven temperature exceeds an acceptable range and when the countdown timer hits zero. I'm using IFTTT's webhooks service for this, and getting notifications (with a little payload data) to works was straightforward. I'll cover this in an upcoming blog post (I plan on automatically setting an alarm on the user's phone too!).
  • Stretch goal 1: Using the Sense HAT
  • Sign in to reply

Top Comments

  • three-phase
    three-phase over 7 years ago +2
    Nice update, well done for getting this far with your project. Kind regards
  • genebren
    genebren over 7 years ago +1
    Another great update. Keep up the good work! Gene
  • genebren
    genebren over 7 years ago

    Another great update.  Keep up the good work!

    Gene

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • three-phase
    three-phase over 7 years ago

    Nice update, well done for getting this far with your project.

     

    Kind regards

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube