├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── githubci.yml ├── .gitignore ├── Adafruit_MCP9808.cpp ├── Adafruit_MCP9808.h ├── README.md ├── assets └── board.jpg ├── code-of-conduct.md ├── examples ├── MCP9808_oleddemo │ └── MCP9808_oleddemo.ino └── mcp9808test │ └── mcp9808test.ino ├── library.properties └── license.txt /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening an issue on an Adafruit Arduino library repository. To 2 | improve the speed of resolution please review the following guidelines and 3 | common troubleshooting steps below before creating the issue: 4 | 5 | - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use 6 | the forums at http://forums.adafruit.com to ask questions and troubleshoot why 7 | something isn't working as expected. In many cases the problem is a common issue 8 | that you will more quickly receive help from the forum community. GitHub issues 9 | are meant for known defects in the code. If you don't know if there is a defect 10 | in the code then start with troubleshooting on the forum first. 11 | 12 | - **If following a tutorial or guide be sure you didn't miss a step.** Carefully 13 | check all of the steps and commands to run have been followed. Consult the 14 | forum if you're unsure or have questions about steps in a guide/tutorial. 15 | 16 | - **For Arduino projects check these very common issues to ensure they don't apply**: 17 | 18 | - For uploading sketches or communicating with the board make sure you're using 19 | a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes 20 | very hard to tell the difference between a data and charge cable! Try using the 21 | cable with other devices or swapping to another cable to confirm it is not 22 | the problem. 23 | 24 | - **Be sure you are supplying adequate power to the board.** Check the specs of 25 | your board and plug in an external power supply. In many cases just 26 | plugging a board into your computer is not enough to power it and other 27 | peripherals. 28 | 29 | - **Double check all soldering joints and connections.** Flakey connections 30 | cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. 31 | 32 | - **Ensure you are using an official Arduino or Adafruit board.** We can't 33 | guarantee a clone board will have the same functionality and work as expected 34 | with this code and don't support them. 35 | 36 | If you're sure this issue is a defect in the code and checked the steps above 37 | please fill in the following fields to provide enough troubleshooting information. 38 | You may delete the guideline and text above to just leave the following details: 39 | 40 | - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** 41 | 42 | - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO 43 | VERSION HERE** 44 | 45 | - List the steps to reproduce the problem below (if possible attach a sketch or 46 | copy the sketch code in too): **LIST REPRO STEPS BELOW** 47 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /.github/workflows/githubci.yml: -------------------------------------------------------------------------------- 1 | name: Arduino Library CI 2 | 3 | on: [pull_request, push, repository_dispatch] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/setup-python@v4 11 | with: 12 | python-version: '3.x' 13 | - uses: actions/checkout@v3 14 | - uses: actions/checkout@v3 15 | with: 16 | repository: adafruit/ci-arduino 17 | path: ci 18 | 19 | - name: pre-install 20 | run: bash ci/actions_install.sh 21 | 22 | - name: test platforms 23 | run: python3 ci/build_platform.py main_platforms 24 | 25 | - name: clang 26 | run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . 27 | 28 | - name: doxygen 29 | env: 30 | GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} 31 | PRETTYNAME : "Adafruit MCP9808 Arduino Library" 32 | run: bash ci/doxy_gen_and_deploy.sh 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # osx 2 | .DS_Store 3 | 4 | # doxygen 5 | Doxyfile* 6 | doxygen_sqlite3.db 7 | html 8 | *.tmp 9 | -------------------------------------------------------------------------------- /Adafruit_MCP9808.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_MCP9808.cpp 3 | * 4 | * @mainpage Adafruit MCP9808 I2C Temp Sensor 5 | * 6 | * @section intro_sec Introduction 7 | * 8 | * I2C Driver for Microchip's MCP9808 I2C Temp sensor 9 | * 10 | * This is a library for the Adafruit MCP9808 breakout: 11 | * http://www.adafruit.com/products/1782 12 | * 13 | * Adafruit invests time and resources providing this open source code, 14 | * please support Adafruit and open-source hardware by purchasing products from 15 | * Adafruit! 16 | * 17 | * @section author Author 18 | * 19 | * K.Townsend (Adafruit Industries) 20 | * 21 | * @section license License 22 | * 23 | * BSD (see license.txt) 24 | * 25 | * @section HISTORY 26 | * 27 | * v1.0 - First release 28 | */ 29 | 30 | #include "Adafruit_MCP9808.h" 31 | 32 | /*! 33 | * @brief Instantiates a new MCP9808 class 34 | */ 35 | Adafruit_MCP9808::Adafruit_MCP9808() {} 36 | 37 | /*! 38 | * @brief Setups the HW 39 | * @param *theWire 40 | * @return True if initialization was successful, otherwise false. 41 | */ 42 | bool Adafruit_MCP9808::begin(TwoWire *theWire) { 43 | return begin(MCP9808_I2CADDR_DEFAULT, theWire); 44 | } 45 | 46 | /*! 47 | * @brief Setups the HW 48 | * @param addr 49 | * @return True if initialization was successful, otherwise false. 50 | */ 51 | 52 | bool Adafruit_MCP9808::begin(uint8_t addr) { return begin(addr, &Wire); } 53 | 54 | /*! 55 | * @brief Setups the HW 56 | * @param addr 57 | * @param *theWire 58 | * @return True if initialization was successful, otherwise false. 59 | */ 60 | bool Adafruit_MCP9808::begin(uint8_t addr, TwoWire *theWire) { 61 | if (i2c_dev) { 62 | delete i2c_dev; 63 | } 64 | i2c_dev = new Adafruit_I2CDevice(addr, theWire); 65 | 66 | return init(); 67 | } 68 | 69 | /*! 70 | * @brief Setups the HW with default address 71 | * @return True if initialization was successful, otherwise false. 72 | */ 73 | bool Adafruit_MCP9808::begin() { return begin(MCP9808_I2CADDR_DEFAULT, &Wire); } 74 | 75 | /*! 76 | * @brief init function 77 | * @return True if initialization was successful, otherwise false. 78 | */ 79 | bool Adafruit_MCP9808::init() { 80 | if (!i2c_dev->begin()) { 81 | return false; 82 | } 83 | 84 | if (read16(MCP9808_REG_MANUF_ID) != 0x0054) 85 | return false; 86 | if (read16(MCP9808_REG_DEVICE_ID) != 0x0400) 87 | return false; 88 | 89 | write16(MCP9808_REG_CONFIG, 0x0); 90 | return true; 91 | } 92 | 93 | /*! 94 | * @brief Reads the 16-bit temperature register and returns the Centigrade 95 | * temperature as a float. 96 | * @return Temperature in Centigrade. 97 | */ 98 | float Adafruit_MCP9808::readTempC() { 99 | float temp = NAN; 100 | uint16_t t = read16(MCP9808_REG_AMBIENT_TEMP); 101 | 102 | if (t != 0xFFFF) { 103 | temp = t & 0x0FFF; 104 | temp /= 16.0; 105 | if (t & 0x1000) 106 | temp -= 256; 107 | } 108 | 109 | return temp; 110 | } 111 | 112 | /*! 113 | * @brief Reads the 16-bit temperature register and returns the Fahrenheit 114 | * temperature as a float. 115 | * @return Temperature in Fahrenheit. 116 | */ 117 | float Adafruit_MCP9808::readTempF() { 118 | float temp = NAN; 119 | uint16_t t = read16(MCP9808_REG_AMBIENT_TEMP); 120 | 121 | if (t != 0xFFFF) { 122 | temp = t & 0x0FFF; 123 | temp /= 16.0; 124 | if (t & 0x1000) 125 | temp -= 256; 126 | 127 | temp = temp * 9.0 / 5.0 + 32; 128 | } 129 | 130 | return temp; 131 | } 132 | 133 | /*! 134 | * @brief Set Sensor to Shutdown-State or wake up (Conf_Register BIT8) 135 | * @param sw true = shutdown / false = wakeup 136 | */ 137 | void Adafruit_MCP9808::shutdown_wake(boolean sw) { 138 | uint16_t conf_shutdown; 139 | uint16_t conf_register = read16(MCP9808_REG_CONFIG); 140 | if (sw == true) { 141 | conf_shutdown = conf_register | MCP9808_REG_CONFIG_SHUTDOWN; 142 | write16(MCP9808_REG_CONFIG, conf_shutdown); 143 | } 144 | if (sw == false) { 145 | conf_shutdown = conf_register & ~MCP9808_REG_CONFIG_SHUTDOWN; 146 | write16(MCP9808_REG_CONFIG, conf_shutdown); 147 | } 148 | } 149 | 150 | /*! 151 | * @brief Shutdown MCP9808 152 | */ 153 | void Adafruit_MCP9808::shutdown() { shutdown_wake(true); } 154 | 155 | /*! 156 | * @brief Wake up MCP9808 157 | */ 158 | void Adafruit_MCP9808::wake() { 159 | shutdown_wake(false); 160 | delay(260); 161 | } 162 | 163 | /*! 164 | * @brief Get Resolution Value 165 | * @return Resolution value 166 | */ 167 | uint8_t Adafruit_MCP9808::getResolution() { 168 | return read8(MCP9808_REG_RESOLUTION); 169 | } 170 | 171 | /*! 172 | * @brief Set Resolution Value 173 | * @param value 174 | */ 175 | void Adafruit_MCP9808::setResolution(uint8_t value) { 176 | write8(MCP9808_REG_RESOLUTION, value & 0x03); 177 | } 178 | 179 | /*! 180 | * @brief Low level 16 bit write procedures 181 | * @param reg 182 | * @param value 183 | */ 184 | void Adafruit_MCP9808::write16(uint8_t reg, uint16_t value) { 185 | Adafruit_BusIO_Register reg16 = 186 | Adafruit_BusIO_Register(i2c_dev, reg, 2, MSBFIRST); 187 | 188 | reg16.write(value); 189 | } 190 | 191 | /*! 192 | * @brief Low level 16 bit read procedure 193 | * @param reg 194 | * @return value 195 | */ 196 | uint16_t Adafruit_MCP9808::read16(uint8_t reg) { 197 | Adafruit_BusIO_Register reg16 = 198 | Adafruit_BusIO_Register(i2c_dev, reg, 2, MSBFIRST); 199 | 200 | return reg16.read(); 201 | } 202 | 203 | /*! 204 | * @brief Low level 8 bit write procedure 205 | * @param reg 206 | * @param value 207 | */ 208 | void Adafruit_MCP9808::write8(uint8_t reg, uint8_t value) { 209 | Adafruit_BusIO_Register reg8 = Adafruit_BusIO_Register(i2c_dev, reg, 1); 210 | 211 | reg8.write(value); 212 | } 213 | 214 | /*! 215 | * @brief Low level 8 bit read procedure 216 | * @param reg 217 | * @return value 218 | */ 219 | uint8_t Adafruit_MCP9808::read8(uint8_t reg) { 220 | Adafruit_BusIO_Register reg8 = Adafruit_BusIO_Register(i2c_dev, reg, 1); 221 | 222 | return reg8.read(); 223 | } 224 | 225 | /**************************************************************************/ 226 | /*! 227 | @brief Gets the pressure sensor and temperature values as sensor events 228 | 229 | @param temp Sensor event object that will be populated with temp data 230 | @returns True 231 | */ 232 | /**************************************************************************/ 233 | bool Adafruit_MCP9808::getEvent(sensors_event_t *temp) { 234 | uint32_t t = millis(); 235 | 236 | // use helpers to fill in the events 237 | memset(temp, 0, sizeof(sensors_event_t)); 238 | temp->version = sizeof(sensors_event_t); 239 | temp->sensor_id = _sensorID; 240 | temp->type = SENSOR_TYPE_AMBIENT_TEMPERATURE; 241 | temp->timestamp = t; 242 | temp->temperature = readTempC(); 243 | return true; 244 | } 245 | 246 | /**************************************************************************/ 247 | /*! 248 | @brief Gets the overall sensor_t data including the type, range and 249 | resulution 250 | @param sensor Pointer to Adafruit_Sensor sensor_t object that will be 251 | filled with sensor type data 252 | */ 253 | /**************************************************************************/ 254 | void Adafruit_MCP9808::getSensor(sensor_t *sensor) { 255 | /* Clear the sensor_t object */ 256 | memset(sensor, 0, sizeof(sensor_t)); 257 | 258 | /* Insert the sensor name in the fixed length char array */ 259 | strncpy(sensor->name, "MCP9808", sizeof(sensor->name) - 1); 260 | sensor->name[sizeof(sensor->name) - 1] = 0; 261 | sensor->version = 1; 262 | sensor->sensor_id = _sensorID; 263 | sensor->type = SENSOR_TYPE_AMBIENT_TEMPERATURE; 264 | sensor->min_delay = 0; 265 | sensor->max_value = 100.0; 266 | sensor->min_value = -20.0; 267 | sensor->resolution = 0.0625; 268 | } 269 | /*******************************************************/ 270 | -------------------------------------------------------------------------------- /Adafruit_MCP9808.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_MCP9808.h 3 | * 4 | * I2C Driver for Microchip's MCP9808 I2C Temp sensor 5 | * 6 | * This is a library for the Adafruit MCP9808 breakout: 7 | * http://www.adafruit.com/products/1782 8 | * 9 | * Adafruit invests time and resources providing this open source code, 10 | *please support Adafruit and open-source hardware by purchasing products from 11 | * Adafruit! 12 | * 13 | * 14 | * BSD license (see license.txt) 15 | */ 16 | 17 | #ifndef _ADAFRUIT_MCP9808_H 18 | #define _ADAFRUIT_MCP9808_H 19 | 20 | #include "Adafruit_BusIO_Register.h" 21 | #include "Arduino.h" 22 | #include 23 | #include 24 | 25 | #define MCP9808_I2CADDR_DEFAULT 0x18 ///< I2C address 26 | #define MCP9808_REG_CONFIG 0x01 ///< MCP9808 config register 27 | 28 | #define MCP9808_REG_CONFIG_SHUTDOWN 0x0100 ///< shutdown config 29 | #define MCP9808_REG_CONFIG_CRITLOCKED 0x0080 ///< critical trip lock 30 | #define MCP9808_REG_CONFIG_WINLOCKED 0x0040 ///< alarm window lock 31 | #define MCP9808_REG_CONFIG_INTCLR 0x0020 ///< interrupt clear 32 | #define MCP9808_REG_CONFIG_ALERTSTAT 0x0010 ///< alert output status 33 | #define MCP9808_REG_CONFIG_ALERTCTRL 0x0008 ///< alert output control 34 | #define MCP9808_REG_CONFIG_ALERTSEL 0x0004 ///< alert output select 35 | #define MCP9808_REG_CONFIG_ALERTPOL 0x0002 ///< alert output polarity 36 | #define MCP9808_REG_CONFIG_ALERTMODE 0x0001 ///< alert output mode 37 | 38 | #define MCP9808_REG_UPPER_TEMP 0x02 ///< upper alert boundary 39 | #define MCP9808_REG_LOWER_TEMP 0x03 ///< lower alert boundery 40 | #define MCP9808_REG_CRIT_TEMP 0x04 ///< critical temperature 41 | #define MCP9808_REG_AMBIENT_TEMP 0x05 ///< ambient temperature 42 | #define MCP9808_REG_MANUF_ID 0x06 ///< manufacture ID 43 | #define MCP9808_REG_DEVICE_ID 0x07 ///< device ID 44 | #define MCP9808_REG_RESOLUTION 0x08 ///< resolutin 45 | 46 | /*! 47 | * @brief Class that stores state and functions for interacting with 48 | * MCP9808 Temp Sensor 49 | */ 50 | class Adafruit_MCP9808 : public Adafruit_Sensor { 51 | public: 52 | Adafruit_MCP9808(); 53 | bool begin(); 54 | bool begin(TwoWire *theWire); 55 | bool begin(uint8_t addr); 56 | bool begin(uint8_t addr, TwoWire *theWire); 57 | 58 | bool init(); 59 | float readTempC(); 60 | float readTempF(); 61 | uint8_t getResolution(void); 62 | void setResolution(uint8_t value); 63 | 64 | void shutdown_wake(boolean sw); 65 | void shutdown(); 66 | void wake(); 67 | 68 | void write16(uint8_t reg, uint16_t val); 69 | uint16_t read16(uint8_t reg); 70 | 71 | void write8(uint8_t reg, uint8_t val); 72 | uint8_t read8(uint8_t reg); 73 | 74 | /* Unified Sensor API Functions */ 75 | bool getEvent(sensors_event_t *); 76 | void getSensor(sensor_t *); 77 | 78 | private: 79 | uint16_t _sensorID = 9808; ///< ID number for temperature 80 | Adafruit_I2CDevice *i2c_dev = NULL; 81 | }; 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Adafruit MCP9808 Library [![Build Status](https://github.com/adafruit/Adafruit_MCP9808_Library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_MCP9808_Library/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_MCP9808_Library/html/index.html) 2 | 3 | 4 | 5 | This is the Adafruit MCP9808 Precision I2C Temperature sensor library 6 | 7 | Tested and works great with the Adafruit MCP9808 Breakout Board 8 | * http://www.adafruit.com/products/1782 9 | 10 | This chip uses I2C to communicate, 2 pins are required to interface 11 | 12 | Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! 13 | 14 | Written by Kevin Townsend/Limor Fried for Adafruit Industries. 15 | BSD license, check license.txt for more information 16 | All text above must be included in any redistribution 17 | 18 | To install, use the Arduino Library Manager and search for "Adafruit MCP9808" and install the library. 19 | -------------------------------------------------------------------------------- /assets/board.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_MCP9808_Library/1447e4e8ab099dec3bc76bbb19ab9136f9478b15/assets/board.jpg -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Adafruit Community Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and leaders pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level or type of 9 | experience, education, socio-economic status, nationality, personal appearance, 10 | race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | We are committed to providing a friendly, safe and welcoming environment for 15 | all. 16 | 17 | Examples of behavior that contributes to creating a positive environment 18 | include: 19 | 20 | * Be kind and courteous to others 21 | * Using welcoming and inclusive language 22 | * Being respectful of differing viewpoints and experiences 23 | * Collaborating with other community members 24 | * Gracefully accepting constructive criticism 25 | * Focusing on what is best for the community 26 | * Showing empathy towards other community members 27 | 28 | Examples of unacceptable behavior by participants include: 29 | 30 | * The use of sexualized language or imagery and sexual attention or advances 31 | * The use of inappropriate images, including in a community member's avatar 32 | * The use of inappropriate language, including in a community member's nickname 33 | * Any spamming, flaming, baiting or other attention-stealing behavior 34 | * Excessive or unwelcome helping; answering outside the scope of the question 35 | asked 36 | * Trolling, insulting/derogatory comments, and personal or political attacks 37 | * Public or private harassment 38 | * Publishing others' private information, such as a physical or electronic 39 | address, without explicit permission 40 | * Other conduct which could reasonably be considered inappropriate 41 | 42 | The goal of the standards and moderation guidelines outlined here is to build 43 | and maintain a respectful community. We ask that you don’t just aim to be 44 | "technically unimpeachable", but rather try to be your best self. 45 | 46 | We value many things beyond technical expertise, including collaboration and 47 | supporting others within our community. Providing a positive experience for 48 | other community members can have a much more significant impact than simply 49 | providing the correct answer. 50 | 51 | ## Our Responsibilities 52 | 53 | Project leaders are responsible for clarifying the standards of acceptable 54 | behavior and are expected to take appropriate and fair corrective action in 55 | response to any instances of unacceptable behavior. 56 | 57 | Project leaders have the right and responsibility to remove, edit, or 58 | reject messages, comments, commits, code, issues, and other contributions 59 | that are not aligned to this Code of Conduct, or to ban temporarily or 60 | permanently any community member for other behaviors that they deem 61 | inappropriate, threatening, offensive, or harmful. 62 | 63 | ## Moderation 64 | 65 | Instances of behaviors that violate the Adafruit Community Code of Conduct 66 | may be reported by any member of the community. Community members are 67 | encouraged to report these situations, including situations they witness 68 | involving other community members. 69 | 70 | You may report in the following ways: 71 | 72 | In any situation, you may send an email to . 73 | 74 | On the Adafruit Discord, you may send an open message from any channel 75 | to all Community Helpers by tagging @community helpers. You may also send an 76 | open message from any channel, or a direct message to @kattni#1507, 77 | @tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or 78 | @Andon#8175. 79 | 80 | Email and direct message reports will be kept confidential. 81 | 82 | In situations on Discord where the issue is particularly egregious, possibly 83 | illegal, requires immediate action, or violates the Discord terms of service, 84 | you should also report the message directly to Discord. 85 | 86 | These are the steps for upholding our community’s standards of conduct. 87 | 88 | 1. Any member of the community may report any situation that violates the 89 | Adafruit Community Code of Conduct. All reports will be reviewed and 90 | investigated. 91 | 2. If the behavior is an egregious violation, the community member who 92 | committed the violation may be banned immediately, without warning. 93 | 3. Otherwise, moderators will first respond to such behavior with a warning. 94 | 4. Moderators follow a soft "three strikes" policy - the community member may 95 | be given another chance, if they are receptive to the warning and change their 96 | behavior. 97 | 5. If the community member is unreceptive or unreasonable when warned by a 98 | moderator, or the warning goes unheeded, they may be banned for a first or 99 | second offense. Repeated offenses will result in the community member being 100 | banned. 101 | 102 | ## Scope 103 | 104 | This Code of Conduct and the enforcement policies listed above apply to all 105 | Adafruit Community venues. This includes but is not limited to any community 106 | spaces (both public and private), the entire Adafruit Discord server, and 107 | Adafruit GitHub repositories. Examples of Adafruit Community spaces include 108 | but are not limited to meet-ups, audio chats on the Adafruit Discord, or 109 | interaction at a conference. 110 | 111 | This Code of Conduct applies both within project spaces and in public spaces 112 | when an individual is representing the project or its community. As a community 113 | member, you are representing our community, and are expected to behave 114 | accordingly. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 1.4, available at 120 | , 121 | and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). 122 | 123 | For other projects adopting the Adafruit Community Code of 124 | Conduct, please contact the maintainers of those projects for enforcement. 125 | If you wish to use this code of conduct for your own project, consider 126 | explicitly mentioning your moderation policy or making a copy with your 127 | own moderation policy so as to avoid confusion. 128 | -------------------------------------------------------------------------------- /examples/MCP9808_oleddemo/MCP9808_oleddemo.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire); 7 | 8 | Adafruit_MCP9808 sensor; 9 | 10 | void setup() { 11 | Serial.begin(115200); 12 | //while (!Serial); 13 | 14 | Serial.println("128x64 OLED FeatherWing test"); 15 | display.begin(0x3C, true); // Address 0x3C default 16 | 17 | Serial.println("OLED begun"); 18 | 19 | // Show image buffer on the display hardware. 20 | // Since the buffer is intialized with an Adafruit splashscreen 21 | // internally, this will display the splashscreen. 22 | display.display(); 23 | delay(1000); 24 | 25 | // Clear the buffer. 26 | display.clearDisplay(); 27 | display.display(); 28 | 29 | if (!sensor.begin()) { 30 | Serial.println("Failed to find Adafruit MCP9808 chip"); 31 | while (1) { delay(10); } 32 | } 33 | 34 | Serial.println("MCP9808 Found!"); 35 | 36 | display.setRotation(1); 37 | display.setFont(&FreeSans9pt7b); 38 | display.setTextColor(SH110X_WHITE); 39 | } 40 | 41 | void loop() { 42 | sensors_event_t event; 43 | sensor.getEvent(&event); 44 | 45 | Serial.print("Temperature: "); 46 | Serial.print(event.temperature); 47 | Serial.println(" degrees C"); 48 | Serial.println(""); 49 | 50 | display.clearDisplay(); 51 | display.setCursor(0, 25); 52 | display.println("~ MCP9808 ~"); 53 | display.print("Temp: "); 54 | display.print(event.temperature); 55 | display.println(" C"); 56 | 57 | display.display(); 58 | yield(); 59 | delay(100); 60 | } 61 | -------------------------------------------------------------------------------- /examples/mcp9808test/mcp9808test.ino: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************/ 3 | /*! 4 | This is a demo for the Adafruit MCP9808 breakout 5 | ----> http://www.adafruit.com/products/1782 6 | Adafruit invests time and resources providing this open source code, 7 | please support Adafruit and open-source hardware by purchasing 8 | products from Adafruit! 9 | */ 10 | /**************************************************************************/ 11 | 12 | #include 13 | #include "Adafruit_MCP9808.h" 14 | 15 | // Create the MCP9808 temperature sensor object 16 | Adafruit_MCP9808 tempsensor = Adafruit_MCP9808(); 17 | 18 | void setup() { 19 | Serial.begin(9600); 20 | while (!Serial); //waits for serial terminal to be open, necessary in newer arduino boards. 21 | Serial.println("MCP9808 demo"); 22 | 23 | // Make sure the sensor is found, you can also pass in a different i2c 24 | // address with tempsensor.begin(0x19) for example, also can be left in blank for default address use 25 | // Also there is a table with all addres possible for this sensor, you can connect multiple sensors 26 | // to the same i2c bus, just configure each sensor with a different address and define multiple objects for that 27 | // A2 A1 A0 address 28 | // 0 0 0 0x18 this is the default address 29 | // 0 0 1 0x19 30 | // 0 1 0 0x1A 31 | // 0 1 1 0x1B 32 | // 1 0 0 0x1C 33 | // 1 0 1 0x1D 34 | // 1 1 0 0x1E 35 | // 1 1 1 0x1F 36 | if (!tempsensor.begin(0x18)) { 37 | Serial.println("Couldn't find MCP9808! Check your connections and verify the address is correct."); 38 | while (1); 39 | } 40 | 41 | Serial.println("Found MCP9808!"); 42 | 43 | tempsensor.setResolution(3); // sets the resolution mode of reading, the modes are defined in the table bellow: 44 | // Mode Resolution SampleTime 45 | // 0 0.5°C 30 ms 46 | // 1 0.25°C 65 ms 47 | // 2 0.125°C 130 ms 48 | // 3 0.0625°C 250 ms 49 | } 50 | 51 | void loop() { 52 | Serial.println("wake up MCP9808.... "); // wake up MCP9808 - power consumption ~200 mikro Ampere 53 | tempsensor.wake(); // wake up, ready to read! 54 | 55 | // Read and print out the temperature, also shows the resolution mode used for reading. 56 | Serial.print("Resolution in mode: "); 57 | Serial.println (tempsensor.getResolution()); 58 | float c = tempsensor.readTempC(); 59 | float f = tempsensor.readTempF(); 60 | Serial.print("Temp: "); 61 | Serial.print(c, 4); Serial.print("*C\t and "); 62 | Serial.print(f, 4); Serial.println("*F."); 63 | 64 | delay(2000); 65 | Serial.println("Shutdown MCP9808.... "); 66 | tempsensor.shutdown_wake(1); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere, stops temperature sampling 67 | Serial.println(""); 68 | delay(200); 69 | } 70 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit MCP9808 Library 2 | version=2.0.2 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Arduino library for the MCP9808 sensors in the Adafruit shop 6 | paragraph=Arduino library for the MCP9808 sensors in the Adafruit shop 7 | category=Sensors 8 | url=https://github.com/adafruit/Adafruit_MCP9808_Library 9 | architectures=* 10 | depends=Adafruit Unified Sensor, Adafruit BusIO, Adafruit SH110X 11 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012, Adafruit Industries 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of the copyright holders nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | --------------------------------------------------------------------------------