About Us Knowledge Base Community Forum Electronics Toolbox FAQ Shipping & Delivery

Community Forum

Share your projects and post your questions

Search
Register or Sign In
Forum

Storing 0.0005 in memory

1462 Views - Created 26/01/2017

26/01/2017

Posted by:
Johnu

Users Avatar

Im new to python but getting there writing for my project but am stuck on using the memory storage on the RTC using the example code. What am I mssing to store a number libe 0.0005

26/01/2017

Posted by:
Johnu

Last edited: 26/01/2017

Users Avatar

Sorry - new to the forum as well
 
 

26/01/2017

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

Hi

The RTC memory example would only work with whole numbers as it saved the value as an integer.  I have created a new python script which shows how you can save a number with decimal places to the RTC memory.  You can view the file at https://github.com/abelectronicsuk/ABElectronics_Python_Libraries/blob/master/RTCPi/demos/demo_rtcmemory_double.py

To save a number to the memory you have to convert it into an array of bytes.  As the number you want to save is not a whole number it would have to be saved as a double which contains 8 bytes.  I created two functions double_to_array() and array_to_double() that you can use to convert the number from a double into an array of bytes and back again.

Hopefully you can use this example to get your project working.

AB Electronics UK Tech Support

26/01/2017

Posted by:
Johnu

Users Avatar

Thanks Andrew I now understand that bit.

If I wanted to run both of those functions under one function call and pass the varaiable into it, is that poosible?

Im having problems passing variables between functions and in and out of functions

John

 

 

 

26/01/2017

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

Do you mean combine the code from both the functions into a single function or call both functions from another function?  As the double_to_array() and array_to_double() functions take different data types as inputs, an array of bytes and a double, it would be difficult to make combine them together. 

If you are having trouble passing variables then it may be worth reading this page on how functions work in python.  The main cause of problems I normally find is trying to pass the wrong data type of number of arguments into the functions.

AB Electronics UK Tech Support

Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view, download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.