Using examples

Hi All,
Being a nuby I try using the examples found with the various libraries, but have trouble working out how to connect to which pins etc. since most of the examples don’t specify which pins they are using. Is there some where I might be able to get some clues on this ?
Cheers… Blakus

Please give examples of the libraries that you have problems with.

The examples will have variables set to a certain I/O pin number or the sketch will directly use I/O pin numbers in the lines of code.

Experience will soon be your guiding light.

Blakus: since most of the examples don't specify which pins they are using. Is there some where I might be able to get some clues on this

If you post one of the programs you are having a problem with and we explain how to make sense of it then you will probably be able to figure out the others.

...R

Thanks to all, I have problems with my library locations since the last update. I'll continue when I get it sorted. Cheers .... Blakus

Some library examples, those that use I2C or SPI for instance, may assume that you connect some pins without giving the numbers.

For I2C you will need to connect up SDA and SCL pins, and for SPI you need to connect SCK, MOSI and MISO pins.

Thanks,
I am trying this example,

@section Demoauthor Author

Written by Arnd\@SV-Zanshin

@section Demoversions Changelog

Version | Date       | Developer                     | Comments
------- | ---------- | ----------------------------- | ---------------------------------------------------
1.0.1   | 2019-02-02 | https://github.com/SV-Zanshin | Issue #4 - Convert program comments and style to Doxygen
1.0.0   | 2017-08-12 | https://github.com/SV-Zanshin | Finished, first release
1.0.0a  | 2017-08-11 | https://github.com/SV-Zanshin | Initial coding
*/
#include <MAX31855.h> // Include MAX31855 Sensor library
/*******************************************************************************************************************
** Declare all program constants                                                                                  **
*******************************************************************************************************************/
const uint32_t SERIAL_SPEED     = 115200; ///< Set the baud rate for Serial I/O
const uint8_t  SPI_CHIP_SELECT  =      2; ///< Chip-Select PIN for SPI
const uint8_t  SPI_MISO         =   MISO; ///< Master-In, Slave-Out PIN for SPI
const uint8_t  SPI_SYSTEM_CLOCK =    SCK; ///< System Clock PIN for SPI

/*******************************************************************************************************************
** Declare global variables and instantiate classes                                                               **
*******************************************************************************************************************/
MAX31855_Class MAX31855; ///< Create an instance of MAX31855

/***************************************************************************************************************//*!
* @brief    Arduino method called once at startup to initialize the system
* @details  This is an Arduino IDE method which is called first upon boot or restart. It is only called one time
*           and then control goes to the main "loop()" method, from which control never returns
* @return   void
*******************************************************************************************************************/
void setup()
{
  Serial.begin(SERIAL_SPEED);
  #ifdef  __AVR_ATmega32U4__  // If this is a 32U4 processor, then wait 3 seconds for the interface to initialize
    delay(3000);
  #endif
  Serial.println(F("Starting software SPI demo program for MAX31855"));
  Serial.print(F("Initializing MAX31855 sensor\n"));
  /********************************************************************************************
  ** Uncomment out either the hardware or software SPI call, depending upon which is in use  **
  ********************************************************************************************/
  while (!MAX31855.begin(SPI_CHIP_SELECT))                            // Hardware SPI for MAX31855
//while (!MAX31855.begin(SPI_CHIP_SELECT,SPI_MISO,SPI_SYSTSEM_CLOCK)) // Software SPI for MAX31855
  {
    Serial.println(F("Unable to start MAX31855. Waiting 3 seconds."));
    delay(3000);
  } // of loop until device is located
 Serial.println();
} // of method setup()

/***************************************************************************************************************//*!
* @brief    Arduino method for the main program loop
* @details  This is the main program for the Arduino IDE, it is an infinite loop and keeps on repeating.
* @return   void
*******************************************************************************************************************/
void loop()
{
  int32_t ambientTemperature = MAX31855.readAmbient(); // retrieve MAX31855 die ambient temperature
  int32_t probeTemperature   = MAX31855.readProbe();   // retrieve thermocouple probe temp
  uint8_t faultCode          = MAX31855.fault();       // retrieve any error codes
  if ( faultCode )                                     // Display error code if present
  {
    Serial.print("Fault code ");
    Serial.print(faultCode);
    Serial.println(" returned.");
  }
  else
  {
    Serial.print("Ambient Temperature is ");
    Serial.print((float)ambientTemperature/1000,3);
    Serial.println("\xC2\xB0""C");
    Serial.print("Probe Temperature is   ");
    Serial.print((float)probeTemperature/1000,3);
    Serial.println("\xC2\xB0""C\n");
  } // of if-then-else an error occurred
  delay(5000);
} // of method loop()

I can follow connecting the SCK and MISO pins on the ICSP socket but would I be correct in taking analog pin 2 for the chip select? that leaves MOSI to connect, presumably on the ICSP socket ?
Also would this be using the SPI software? How is that determind, would it be hardware for using the ICSP socket and software using the pins?
Also I would prefer to use the I2C bus is there a convention for the pins to connect SDA and SCL ?

Cheers … Blakus

There are a dozen + different Arduinos with different pinouts and different Vcc voltages. Why not tell us WHICH ONE you have?

JCA34F:
There are a dozen + different Arduinos with different pinouts and different Vcc voltages. Why not tell us WHICH ONE you have?

So frightfully sorry, I have a uno clone for this.

For the example you gave, 2 is a digital pin. If that's already in use, you can change it.

If you want to use A2, change it to A2.

uint8_t uint8_t  SPI_CHIP_SELECT = A2;

You don't need MOSI as far as I can see; the MAX31855 seems to be a sensor and you will only read from it.

You'll need to study a little how SPI works and what MISO and MOSI stand for.

Blakus: I can follow connecting the SCK and MISO pins on the ICSP socket but would I be correct in taking analog pin 2 for the chip select?

On an Uno MISO is pin 12 and SCK is pin 13 (MOSI is pin 11, but it seems you don't need it) and Pin2 normally means digital pin 2.

You an also connect MISO and SCK to the ISP header pins if you prefer - they are electrically identical.

When using SPI you may use any pin for chip select, but you MUST have pin 10 set as OUTPUT (whether used for SPI purposes or not) to ensure that the Arduino acts as SPI master.

You would have to re-write the library code if you want to use I2C.

...R

Thanks, I've been looking for info onthe module but not had much luck. The chip select pin, does it need to be high or low to select it ? I couldn't see where the pin 10 was set high in the code, is it this line ?

" while (!MAX31855.begin(SPI_CHIP_SELECT)) // Hardware SPI for MAX31855 "

I'll check around for info on SPI

Cheers .... Blakus

The Atmega 328 datasheet has all the details about how to use SPI including some short example programs.

...R

The library's begin() method calls SPI.begin() which sets the SS pin.

// Edit to add

The library's begin method also sets the CS pin to output and makes it HIGH; when a read is required, it will make the CS pin LOW.

You can find this in the library's cpp file. Search the file for e.g. ::begin and ::readRaw . It might be a bit over your head but you might gain a little understanding.

You can also search your PC for the SPI stuff (SPI.cpp and SPI.h).