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
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum need .py code for reading Max31855 A/D temp converter
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 32 replies
  • Answers 2 answers
  • Subscribers 679 subscribers
  • Views 4973 views
  • Users 0 members are here
  • raspberry_pi
  • raspberrypi
  • adafruit
Related

need .py code for reading Max31855 A/D temp converter

donb
donb over 11 years ago

Thru this site I got info on a Adafruit Max31855 module. Now does anyone have the code necessary to read the digital output of this fine little module? I don't have the experience to write the code, but truly need the code to save a very long and steep learning curve.   Don

  • Sign in to reply
  • Cancel
Parents
  • donb
    0 donb over 11 years ago

    for Michael Conners

    Below is the error code I got running the original code from Tackie before any changes

    Same error code when I tried changing to cs_pins = [8] and using other pinout's same as I started with

    Same error code when I tried changing to cs_pins = 24 then clk_pin = 23,and data pin 21, I moved jumpers to corresponding gp header numbers

    When I tried to run the two sudo statements from IDLE 2, I got the last to two statements below

    Is running in the root supposed to give access to /dev/mem ?

    >>> ================================ RESTART ================================

    >>>

    Traceback (most recent call last):

      File "/home/pi/max31855.py", line 175, in <module>

       thermocouples.append(MAX31855(cs_pin, clock_pin, data_pin, units))

    File "/home/pi/max31855.py", line 36, in __init__

       GPIO.setup(self.cs_pin, GPIO.OUT)
    RuntimeError: No access to /dev/mem.  Try running as root!

     

     

     

    >>> sudo python max31855.py

    SyntaxError: invalid syntax

    >>> sudo max31855.py

    SyntaxError: invalid syntax
    >>>

     

    I am more confused than ever now!

    I tried using the triple quotes to comment out the last 18 lines. I didn't get any error codes but no data out either.

    If I may I want to put a few more questions to you!

    1.If I change the pin #'s in the code close to end of the listing just above where I used the triple quotes is that actually changing where the code above it

           is supposed to read thermocouple values and do the chip select.

    2. Is there a way to get all the code lines numbered for easier troubleshooting when error is detected in IDLE?

     

    ONE more question for now:

    In the Tuckie code the last line number in his code is 170 but the error codes generated by the python shell is calling for line 175 and that is not even the end of the code.

    His is counting blank lines. How is that happening?

    Sorry for all the time I take from you but you have helped me a great deal to understand the code.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mconners
    0 mconners over 11 years ago in reply to donb

    Hi Don,

     

    As I said, I don't have that device, I also don't use idle, but here is what I did do,

     

    I downloaded that file, the raw file from https://raw.github.com/Tuckie/max31855/master/max31855.py

     

    i edited the file and replaced

      cs_pins = [4, 17, 18, 24]  with cs_pins = [8]

    clock_pin = 23 with clock_pin = 11

    data_pin = 22 with data_pin = 9

     

    I then did

     

    chmod 755 max31855.py

     

    then

     

    sudo ./max31855.py

     

    chmod 755 changes the permissions of the file to read, write, execute by the owner, read, execute to everyone else, it's octal

     

    the other thing that I did, was the spi setup had me edit the /etc/modprobe.d/raspi-blacklist.conf file, i restored that to the original by uncommenting the line about spi, if you didn't do this, don't worry about it.

     

    This program executed perfectly for me with the changes I mentioned, even though I didin't have the device, it just read 0 all the time

     

    Python is an odd language in that spacing and file formatting is important, deviate and you will get syntax errors

     

    my advice is to redownload the file and make only the changes I suggested, you may have to play with the pin numbers.

     

     

    The last 18 lines of the file are the 'main' routine, commenting those out will do nothing but cause you problems.

     

    Good luck,

     

    Mike

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mconners
    0 mconners over 11 years ago in reply to mconners

    BTW, a # will comment out a single line of python

     

    Mike

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • mconners
    0 mconners over 11 years ago in reply to mconners

    BTW, a # will comment out a single line of python

     

    Mike

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • mconners
    0 mconners over 11 years ago in reply to mconners

    Another thing I failed to address, unix uses access permissions for everything, like I mentioned with the chmod 755 earlier.

     

    /dev/mem has restricted access to normal users, running as root will allow you read write access to /dev/mem, running as root, or executing a file with sudo, will elevate your user to allow access to /dev/mem, which allows you to write to the system memory map to allow access to the gpio controller.

     

    There are ways to change this behavior, but they are more advanced unix system administration functions. Let's get your device working, then you can worry about becoming a l33t sys admin. image

     

    Mike

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • 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