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 677 subscribers
  • Views 4959 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
Reply
  • 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
Children
  • 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
  • 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
  • donb
    0 donb over 11 years ago in reply to mconners

    Thanks again for all your time. I will try your suggestions and hope for the same results.

     

    Don

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

    when I run this line (chmod 755 max31855.py)  on LX terminal I get:

    bash: cmod: command not found

     

    When I run this line on IDLE (python shell) I get:

    SyntaxError: invalid syntax

     

    How should I execute this commands?

     

    Thanks again Don

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

    when I run this line (chmod 755 max31855.py)  on LX terminal I get:

    bash: cmod: command not found

     

    When I run this line on IDLE (python shell) I get:

    SyntaxError: invalid syntax

     

             

     

     

    These should be run from a shell prompt

     

    The first error says cmod: command not found

    it should be chmod, make sure you typed it in properly,

     

    the second error is because you are trying to run shell commands in the python console.

     

    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

    Oh, and yes, LXTerminal is the proper window to enter these commands.

     

    Mike

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

    I made a typo when I ran the command the last time to get the result to type to you.

    What actually happens is in the LX terminal, typing in the command  chmod 755 max31855.py

    I get no action at all just a pi@raspberrypi prompt back so I type in sudo ./max31855.py I get:

      sudo: unable to execute ./max31855.py: No such file or directory

    I am thinking the name should be the same with just the attributes changed, is this correct?

    Am I missing a file on the SD card?

    What should the file look like in the directory? I can't find any info in my doc's that tell me what ./ means!

     

    Don

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

    If you have a bunch of commands you do often, you can put them together in a socalled batch file. Or we call it "shell script" in the Unix-world.

    so you can create a file with:

    echo The time is

    date

    in it. But the system likes to know what "interpreter" to use for this script. (there are multiple).  So in this case you add:

     

    #!/bin/sh

     

    as the first line and it uses the shell "/bin/sh".

     

    Now if you store this as test1, and then chmod 755 test1, you can execute this small program with "./test1".


    If, however you type: ./test2, you'll get "no such file or directory" as the error message.
    The confusing thing is: if the first line is wrong, you'll get the same error message. So in my example, if the first line would have been:

    #!/bin/sh2

    the error message will also be: "./test1: no such file or directory"

     

    So... with that error message, you should take a gooooood look at the first line of your max31855 script!

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

     

    What actually happens is in the LX terminal, typing in the command  chmod 755 max31855.py

    I get no action at all just a pi@raspberrypi prompt back so I type in sudo ./max31855.py I get:

     

    That is normal, that means the command executed without error, in *nix, no news is often good news

    if you were to do

    ls -al max31855.py

     

    you should see something like

     

    -rwxr-xr-x 1 pi pi 6171 Feb 14 20:13 max31855.py

     

    in the output, that means you have set the (r)ead,(w)rite,and e(x)ecute bits for the owner

    this is good

     

    the prefix ./ simply means, in the current directory (./) find the file, and in this case execute it,

    so

     

    sudo ./max31855.py

     

    means execute max31855.py as the super user

     

    now the first line of that file, if you did as I said and downloaded it again, will have

    #!/usr/bin/python

     

    that means, use /usr/bin/python  to interpret the following commands contained in the file.

     

    if you type

    which python

     

    at the command line, you should be treated to the output

     

    /usr/bin/python

     

    if it does not print that, then your python interpreter is installed in another location, and that should be the first line of your program.

     

    I'm realizing that you are very new to all of this, but it's ok, that is what we are here for.

     

    Good luck,

     

    Mike

     

    PS. I can't wait for you to get this to work.

    • Cancel
    • Vote Up +1 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