JChristensen / Thermocouple

Thermocouple library for Arduino and MAX6675
http://adventuresinarduinoland.blogspot.com/
11 stars 6 forks source link

Your LIB doesn't work with other SPI devices #1

Open yoram-s opened 6 years ago

yoram-s commented 6 years ago

Hi, You have to adjust your lib to support the SPI Transaction option to co-exist with other devices on the SPI bus.

Thermocouple::Thermocouple(int ssPin){
...
    /*
      SPI configuration
      SPI.setBitOrder(MSBFIRST);
      SPI.setDataMode(SPI_MODE1);
     SPI.setClockDivider(SPI_CLOCK_DIV16);   //Set SPI clock freq to 1MHz
  */
    SPI.begin();                              //initialize SPI

float Thermocouple::readC() {
    ...
    SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV16,MSBFIRST,SPI_MODE1));

    digitalWrite(_ssPin, LOW);
    tcData = SPI.transfer(0x00) << 8;
    tcData |= SPI.transfer(0x00);
    digitalWrite(_ssPin, HIGH);

    SPI.endTransaction();
JChristensen commented 6 years ago

Just to be clear, you are saying that the SPI bus should be reinitialized before every transfer in case other devices on the bus operate in different SPI modes?

TSJim commented 5 years ago

Hi JChristensen...

In response to the OP, actually, I have found that the other MAX6675 Arduino libraries seem to not use SPI in a compatible "standard" way. But your library does. So I would expect that your library would work better with other SPI devices when CS is used to switch back and forth.

In my case, I was trying to read 10 MAX6675 thermocouple modules, and send the results out onto CAN bus with an SPI MCP2515 CAN bus module. With the standard Arduino MAX6675 libraries, the sketch would crash as soon as the SPI.begin() was called. As far as I can tell, this is because the other MAX6675 libraries use bit-banging instead of "proper" SPI usage.

Anyway, just wanted to chime in and thank you for your library which worked for me in this case.

BTW, is there a function in your library to do a F or C read without the averaging? Just curious, and I haven't actually opened the lib files to look.

Thanks!

JChristensen commented 5 years ago

Hello @TSJim,

Thanks for your comments. The readC() and readF() functions both return averaged values. I wrote this library a really long time ago and while it may work OK, it could really stand a re-write. I subsequently wrote a Moving Average library so I'd probably remove the averaging functionality from the Thermocouple library. Unfortunately I have other priorities at present. I'm still not clear on exactly what the OP was saying.

Cheers ... jc

TSJim commented 5 years ago

Hi JC...

OK, I really appreciate your reply. The averaging code in the current library will work fine for my application. I was only curious if there were other functions without the averaging, but it seems there are not which is fine.

Thank you for your work on the library, and your reply!

BTW, I'm using your library to read 10 thermocouples which are mounted on an M548A1 military cargo carrier, which we have converted to run completely remote controlled through VR with an Oculus Rift. The vehicle is set up as a sort of robotic firefighting unit. It carries 1200 gallons of water and foam concentrate, and is designed to be operated by firefighters so no humans need to be put at risk. This idea was dreamed up by Jamie Hyneman (former co-host of the MythBusters television series in the US) and I am working with him to make this happen. We are shipping the vehicle to Southern California this weekend for testing in fire.

Cheers!

-- Jim Newton jimn9970@gmail.com 1 (650) 521-2840

On Mon, Sep 10, 2018 at 4:35 AM Jack Christensen notifications@github.com wrote:

Hello @TSJim https://github.com/TSJim,

Thanks for your comments. The readC() and readF() functions both return averaged values. I wrote this library a really long time ago and while it may work OK, it could really stand a re-write. I subsequently wrote a Moving Average library https://github.com/JChristensen/movingAvg so I'd probably remove the averaging functionality from the Thermocouple library. Unfortunately I have other priorities at present. I'm still not clear on exactly what the OP was saying.

Cheers ... jc

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/JChristensen/Thermocouple/issues/1#issuecomment-419882633, or mute the thread https://github.com/notifications/unsubscribe-auth/AX73gUGjKNrmoyslevWO0LOMO3GQzVlhks5uZk6UgaJpZM4Pp6BS .