├── .gitattributes ├── .github └── workflows │ ├── stale.yml │ └── sync_issues.yml ├── .gitignore ├── .gitlab-ci.yml ├── .travis.yml ├── README.md ├── SeeedGrayOLED.cpp ├── SeeedGrayOLED.h ├── SoftwareI2C.cpp ├── SoftwareI2C.h ├── examples ├── OLED_Display │ └── OLED_Display.ino └── SoftwareI2C_Scan │ └── SoftwareI2C_Scan.ino ├── keywords.txt └── library.properties /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: 'Close stale issues and PRs' 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: '0 4 * * *' 7 | 8 | jobs: 9 | stale: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout repository 14 | uses: actions/checkout@v4 15 | 16 | - name: Checkout script repository 17 | uses: actions/checkout@v4 18 | with: 19 | repository: Seeed-Studio/sync-github-all-issues 20 | path: ci 21 | 22 | - name: Run script 23 | run: ./ci/tools/stale.sh 24 | env: 25 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | -------------------------------------------------------------------------------- /.github/workflows/sync_issues.yml: -------------------------------------------------------------------------------- 1 | name: Automate Issue Management 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | - edited 8 | - assigned 9 | - unassigned 10 | - labeled 11 | - unlabeled 12 | - reopened 13 | 14 | jobs: 15 | add_issue_to_project: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Add issue to GitHub Project 19 | uses: actions/add-to-project@v1.0.2 20 | with: 21 | project-url: https://github.com/orgs/Seeed-Studio/projects/17 22 | github-token: ${{ secrets.ISSUE_ASSEMBLE }} 23 | labeled: bug 24 | label-operator: NOT -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | build: 2 | tags: 3 | - nas 4 | script: 5 | - wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh 6 | - chmod +x seeed-arduino-ci.sh 7 | - bash $PWD/seeed-arduino-ci.sh test 8 | 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | language: generic 3 | dist: bionic 4 | sudo: false 5 | cache: 6 | directories: 7 | - ~/arduino_ide 8 | - ~/.arduino15/packages/ 9 | 10 | before_install: 11 | - wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh 12 | 13 | script: 14 | - chmod +x seeed-arduino-ci.sh 15 | - cat $PWD/seeed-arduino-ci.sh 16 | - bash $PWD/seeed-arduino-ci.sh test 17 | 18 | notifications: 19 | email: 20 | on_success: change 21 | on_failure: change 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Arduino_SoftWareI2C [![Build Status](https://travis-ci.com/Seeed-Studio/Arduino_Software_I2C.svg?branch=master)](https://travis-ci.com/Seeed-Studio/Arduino_Software_I2C) 2 | =============== 3 | 4 | 5 | This is an Arduino software I2C Library, you can use the other pin as I2C interface, such D2, D3. 6 | 7 | But, you should know that this library can only act as Master. 8 | 9 | And, Wire.available() is not correctly supported. 10 | 11 | This library include: 12 | 13 | 14 | void begin(int Sda, int Scl); // setup 15 | uchar beginTransmission(uchar addr); // start 16 | uchar endTransmission(); // end 17 | uchar available(); // bytes available for reading 18 | 19 | uchar write(uchar dta); // write a byte 20 | uchar write(uchar len, uchar *dta); // write a array 21 | uchar requestFrom(uchar addr, uchar len); // request some data 22 | uchar read(); // read a byte 23 | 24 | 25 | 26 | begin() is something different from , you have to set pin here. 27 | beginTransmission() return the uchar, original not. 28 | available() return the length set by requestFrom(). 29 | 30 | The others function is just like the hard I2C library. 31 | -------------------------------------------------------------------------------- /SeeedGrayOLED.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SeeedGrayOLED.cpp 3 | SSD1327 Gray OLED Driver Library 4 | 5 | Copyright (c) 2011 seeed technology inc. 6 | Author : Visweswara R 7 | Create Time : Dec 2011 8 | Change Log : 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include "Arduino.h" 26 | 27 | #include 28 | 29 | #include "SeeedGrayOLED.h" 30 | 31 | #if defined(ESP32) 32 | #include 33 | #else 34 | #include 35 | #endif 36 | 37 | #if defined(__arm__) && !defined(PROGMEM) 38 | #define PROGMEM 39 | #define pgm_read_byte(STR) STR 40 | #endif 41 | 42 | // 8x8 Font ASCII 32 - 127 Implemented 43 | // Users can modify this to support more characters(glyphs) 44 | // BasicFont is placed in code memory. 45 | 46 | // This font can be freely used without any restriction(It is placed in public domain) 47 | const unsigned char BasicFont[][8] PROGMEM = { 48 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 49 | {0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x00}, 50 | {0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00}, 51 | {0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, 0x00}, 52 | {0x00, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00, 0x00}, 53 | {0x00, 0x23, 0x13, 0x08, 0x64, 0x62, 0x00, 0x00}, 54 | {0x00, 0x36, 0x49, 0x55, 0x22, 0x50, 0x00, 0x00}, 55 | {0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00}, 56 | {0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x00, 0x00}, 57 | {0x00, 0x41, 0x22, 0x1C, 0x00, 0x00, 0x00, 0x00}, 58 | {0x00, 0x08, 0x2A, 0x1C, 0x2A, 0x08, 0x00, 0x00}, 59 | {0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00}, 60 | {0x00, 0xA0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}, 61 | {0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00}, 62 | {0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}, 63 | {0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x00}, 64 | {0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00}, 65 | {0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x00}, 66 | {0x00, 0x62, 0x51, 0x49, 0x49, 0x46, 0x00, 0x00}, 67 | {0x00, 0x22, 0x41, 0x49, 0x49, 0x36, 0x00, 0x00}, 68 | {0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, 0x00}, 69 | {0x00, 0x27, 0x45, 0x45, 0x45, 0x39, 0x00, 0x00}, 70 | {0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30, 0x00, 0x00}, 71 | {0x00, 0x01, 0x71, 0x09, 0x05, 0x03, 0x00, 0x00}, 72 | {0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00}, 73 | {0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00}, 74 | {0x00, 0x00, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00}, 75 | {0x00, 0x00, 0xAC, 0x6C, 0x00, 0x00, 0x00, 0x00}, 76 | {0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x00}, 77 | {0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x00}, 78 | {0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x00, 0x00}, 79 | {0x00, 0x02, 0x01, 0x51, 0x09, 0x06, 0x00, 0x00}, 80 | {0x00, 0x32, 0x49, 0x79, 0x41, 0x3E, 0x00, 0x00}, 81 | {0x00, 0x7E, 0x09, 0x09, 0x09, 0x7E, 0x00, 0x00}, 82 | {0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00}, 83 | {0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, 0x00}, 84 | {0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C, 0x00, 0x00}, 85 | {0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, 0x00}, 86 | {0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, 0x00}, 87 | {0x00, 0x3E, 0x41, 0x41, 0x51, 0x72, 0x00, 0x00}, 88 | {0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x00}, 89 | {0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, 0x00, 0x00}, 90 | {0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00, 0x00}, 91 | {0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00}, 92 | {0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00}, 93 | {0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F, 0x00, 0x00}, 94 | {0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x00}, 95 | {0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x00}, 96 | {0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, 0x00}, 97 | {0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00, 0x00}, 98 | {0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x00}, 99 | {0x00, 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, 0x00}, 100 | {0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, 0x00, 0x00}, 101 | {0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x00}, 102 | {0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, 0x00}, 103 | {0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00, 0x00}, 104 | {0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, 0x00}, 105 | {0x00, 0x03, 0x04, 0x78, 0x04, 0x03, 0x00, 0x00}, 106 | {0x00, 0x61, 0x51, 0x49, 0x45, 0x43, 0x00, 0x00}, 107 | {0x00, 0x7F, 0x41, 0x41, 0x00, 0x00, 0x00, 0x00}, 108 | {0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00}, 109 | {0x00, 0x41, 0x41, 0x7F, 0x00, 0x00, 0x00, 0x00}, 110 | {0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, 0x00}, 111 | {0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00}, 112 | {0x00, 0x01, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00}, 113 | {0x00, 0x20, 0x54, 0x54, 0x54, 0x78, 0x00, 0x00}, 114 | {0x00, 0x7F, 0x48, 0x44, 0x44, 0x38, 0x00, 0x00}, 115 | {0x00, 0x38, 0x44, 0x44, 0x28, 0x00, 0x00, 0x00}, 116 | {0x00, 0x38, 0x44, 0x44, 0x48, 0x7F, 0x00, 0x00}, 117 | {0x00, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, 0x00}, 118 | {0x00, 0x08, 0x7E, 0x09, 0x02, 0x00, 0x00, 0x00}, 119 | {0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C, 0x00, 0x00}, 120 | {0x00, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, 0x00}, 121 | {0x00, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00}, 122 | {0x00, 0x80, 0x84, 0x7D, 0x00, 0x00, 0x00, 0x00}, 123 | {0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00}, 124 | {0x00, 0x41, 0x7F, 0x40, 0x00, 0x00, 0x00, 0x00}, 125 | {0x00, 0x7C, 0x04, 0x18, 0x04, 0x78, 0x00, 0x00}, 126 | {0x00, 0x7C, 0x08, 0x04, 0x7C, 0x00, 0x00, 0x00}, 127 | {0x00, 0x38, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00}, 128 | {0x00, 0xFC, 0x24, 0x24, 0x18, 0x00, 0x00, 0x00}, 129 | {0x00, 0x18, 0x24, 0x24, 0xFC, 0x00, 0x00, 0x00}, 130 | {0x00, 0x00, 0x7C, 0x08, 0x04, 0x00, 0x00, 0x00}, 131 | {0x00, 0x48, 0x54, 0x54, 0x24, 0x00, 0x00, 0x00}, 132 | {0x00, 0x04, 0x7F, 0x44, 0x00, 0x00, 0x00, 0x00}, 133 | {0x00, 0x3C, 0x40, 0x40, 0x7C, 0x00, 0x00, 0x00}, 134 | {0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00, 0x00}, 135 | {0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00, 0x00}, 136 | {0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, 0x00}, 137 | {0x00, 0x1C, 0xA0, 0xA0, 0x7C, 0x00, 0x00, 0x00}, 138 | {0x00, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x00}, 139 | {0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00, 0x00}, 140 | {0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00}, 141 | {0x00, 0x41, 0x36, 0x08, 0x00, 0x00, 0x00, 0x00}, 142 | {0x00, 0x02, 0x01, 0x01, 0x02, 0x01, 0x00, 0x00}, 143 | {0x00, 0x02, 0x05, 0x05, 0x02, 0x00, 0x00, 0x00} 144 | }; 145 | 146 | void SeeedGrayOLED::init(int IC) { 147 | Drive_IC = IC; 148 | if (Drive_IC == SSD1327) { 149 | sendCommand(0xFD); // Unlock OLED driver IC MCU interface from entering command. i.e: Accept commands 150 | sendCommand(0x12); 151 | sendCommand(0xAE); // Set display off 152 | sendCommand(0xA8); // set multiplex ratio 153 | sendCommand(0x5F); // 96 154 | sendCommand(0xA1); // set display start line 155 | sendCommand(0x00); 156 | sendCommand(0xA2); // set display offset 157 | sendCommand(0x60); 158 | sendCommand(0xA0); // set remap 159 | sendCommand(0x46); 160 | sendCommand(0xAB); // set vdd internal 161 | sendCommand(0x01); // 162 | sendCommand(0x81); // set contrasr 163 | sendCommand(0x53); // 100 nit 164 | sendCommand(0xB1); // Set Phase Length 165 | sendCommand(0X51); // 166 | sendCommand(0xB3); // Set Display Clock Divide Ratio/Oscillator Frequency 167 | sendCommand(0x01); 168 | sendCommand(0xB9); // 169 | sendCommand(0xBC); // set pre_charge voltage/VCOMH 170 | sendCommand(0x08); // (0x08); 171 | sendCommand(0xBE); // set VCOMH 172 | sendCommand(0X07); // (0x07); 173 | sendCommand(0xB6); // Set second pre-charge period 174 | sendCommand(0x01); // 175 | sendCommand(0xD5); // enable second precharge and enternal vsl 176 | sendCommand(0X62); // (0x62); 177 | sendCommand(0xA4); // Set Normal Display Mode 178 | sendCommand(0x2E); // Deactivate Scroll 179 | sendCommand(0xAF); // Switch on display 180 | delay(100); 181 | 182 | // Row Address 183 | sendCommand(0x75); // Set Row Address 184 | sendCommand(0x00); // Start 0 185 | sendCommand(0x5f); // End 95 186 | 187 | 188 | // Column Address 189 | sendCommand(0x15); // Set Column Address 190 | sendCommand(0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED 191 | sendCommand(0x37); // End at (8 + 47)th column. Each Column has 2 pixels(segments) 192 | 193 | // Init gray level for text. Default:Brightest White 194 | grayH = 0xF0; 195 | grayL = 0x0F; 196 | } else if (Drive_IC == SH1107G) { 197 | sendCommand(0xae); //Display OFF 198 | sendCommand(0xd5); // Set Dclk 199 | sendCommand(0x50); // 100Hz 200 | sendCommand(0x20); // Set row address 201 | sendCommand(0x81); // Set contrast control 202 | sendCommand(0x80); 203 | sendCommand(0xa0); // Segment remap 204 | sendCommand(0xa4); // Set Entire Display ON 205 | sendCommand(0xa6); // Normal display 206 | sendCommand(0xad); // Set external VCC 207 | sendCommand(0x80); 208 | sendCommand(0xc0); // Set Common scan direction 209 | sendCommand(0xd9); // Set phase leghth 210 | sendCommand(0x1f); 211 | sendCommand(0xdb); // Set Vcomh voltage 212 | sendCommand(0x27); 213 | sendCommand(0xaf); //Display ON 214 | sendCommand(0xb0); 215 | sendCommand(0x00); 216 | sendCommand(0x11); 217 | } 218 | } 219 | 220 | void SeeedGrayOLED::sendCommand(unsigned char command) { 221 | Wire->beginTransmission(SeeedGrayOLED_Address); // begin I2C communication 222 | Wire->write(SeeedGrayOLED_Command_Mode); // Set OLED Command mode 223 | Wire->write(command); 224 | Wire->endTransmission(); // End I2C communication 225 | } 226 | 227 | void SeeedGrayOLED::setContrastLevel(unsigned char ContrastLevel) { 228 | sendCommand(SeeedGrayOLED_Set_ContrastLevel_Cmd); 229 | sendCommand(ContrastLevel); 230 | } 231 | 232 | void SeeedGrayOLED::setHorizontalMode() { 233 | if (Drive_IC == SSD1327) { 234 | sendCommand(0xA0); // remap to 235 | sendCommand(0x42); // horizontal mode 236 | 237 | // Row Address 238 | sendCommand(0x75); // Set Row Address 239 | sendCommand(0x00); // Start 0 240 | sendCommand(0x5f); // End 95 241 | 242 | // Column Address 243 | sendCommand(0x15); // Set Column Address 244 | sendCommand(0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED 245 | sendCommand(0x37); // End at (8 + 47)th column. Each Column has 2 pixels(or segments) 246 | } else if (Drive_IC == SH1107G) { 247 | sendCommand(0xA0); 248 | sendCommand(0xC8); 249 | } 250 | } 251 | 252 | void SeeedGrayOLED::setVerticalMode() { 253 | if (Drive_IC == SSD1327) { 254 | sendCommand(0xA0); // remap to 255 | sendCommand(0x46); // Vertical mode 256 | } else if (Drive_IC == SH1107G) { 257 | sendCommand(0xA0); 258 | sendCommand(0xC0); 259 | } 260 | } 261 | 262 | void SeeedGrayOLED::setTextXY(unsigned char Row, unsigned char Column) { 263 | if (Drive_IC == SSD1327) { 264 | //Column Address 265 | sendCommand(0x15); /* Set Column Address */ 266 | sendCommand(0x08 + (Column * 4)); /* Start Column: Start from 8 */ 267 | sendCommand(0x37); /* End Column */ 268 | // Row Address 269 | sendCommand(0x75); /* Set Row Address */ 270 | sendCommand(0x00 + (Row * 8)); /* Start Row*/ 271 | sendCommand(0x07 + (Row * 8)); /* End Row*/ 272 | } else if (Drive_IC == SH1107G) { 273 | uint8_t col_l; 274 | 275 | Column % 2 ? col_l = 0x08 : col_l = 0x00; 276 | sendCommand(0xb0 + Row); 277 | sendCommand(col_l); 278 | sendCommand(0x11 + (Column / 2)); 279 | } 280 | } 281 | 282 | void SeeedGrayOLED::clearDisplay() { 283 | unsigned char i, j; 284 | 285 | if (Drive_IC == SSD1327) { 286 | for (j = 0; j < 48; j++) { 287 | for (i = 0; i < 96; i++) { //clear all columns 288 | sendData(0x00); 289 | } 290 | } 291 | } else if (Drive_IC == SH1107G) { 292 | for (i = 0; i < 16; i++) { 293 | sendCommand(0xb0 + i); 294 | sendCommand(0x0); 295 | sendCommand(0x10); 296 | for (j = 0; j < 128; j++) { 297 | sendData(0x00); 298 | } 299 | } 300 | } 301 | } 302 | 303 | void SeeedGrayOLED::sendData(unsigned char Data) { 304 | Wire->beginTransmission(SeeedGrayOLED_Address); // begin I2C transmission 305 | Wire->write(SeeedGrayOLED_Data_Mode); // data mode 306 | Wire->write(Data); 307 | Wire->endTransmission(); // stop I2C transmission 308 | } 309 | 310 | void SeeedGrayOLED::setGrayLevel(unsigned char grayLevel) { 311 | grayH = (grayLevel << 4) & 0xF0; 312 | grayL = grayLevel & 0x0F; 313 | } 314 | 315 | void SeeedGrayOLED::putChar(unsigned char C) { 316 | if (C < 32 || C > 127) { //Ignore non-printable ASCII characters. This can be modified for multilingual font. 317 | C = ' '; //Space 318 | } 319 | 320 | if (Drive_IC == SSD1327) { 321 | for (char i = 0; i < 8; i = i + 2) { 322 | for (char j = 0; j < 8; j++) { 323 | // Character is constructed two pixel at a time using vertical mode from the default 8x8 font 324 | char c = 0x00; 325 | char bit1 = (pgm_read_byte(&BasicFont[C - 32][(uint8_t) i]) >> j) & 0x01; 326 | char bit2 = (pgm_read_byte(&BasicFont[C - 32][(uint8_t) i + 1]) >> j) & 0x01; 327 | // Each bit is changed to a nibble 328 | c |= (bit1) ? grayH : 0x00; 329 | c |= (bit2) ? grayL : 0x00; 330 | 331 | sendData(c); 332 | } 333 | } 334 | } else if (Drive_IC == SH1107G) { 335 | for (int i = 0; i < 8; i++) { 336 | //read bytes from code memory 337 | sendData(pgm_read_byte(&BasicFont[C - 32][i])); //font array starts at 0, ASCII starts at 32. Hence the translation 338 | } 339 | } 340 | } 341 | 342 | void SeeedGrayOLED::putString(const char* String) { 343 | unsigned char i = 0; 344 | while (String[i]) { 345 | putChar(String[i]); 346 | i++; 347 | } 348 | } 349 | 350 | unsigned char SeeedGrayOLED::putNumber(long long_num) { 351 | unsigned char char_buffer[10] = ""; 352 | unsigned char i = 0; 353 | unsigned char f = 0; 354 | 355 | if (long_num < 0) { 356 | f = 1; 357 | putChar('-'); 358 | long_num = -long_num; 359 | } else if (long_num == 0) { 360 | f = 1; 361 | putChar('0'); 362 | return f; 363 | } 364 | 365 | while (long_num > 0) { 366 | char_buffer[i++] = long_num % 10; 367 | long_num /= 10; 368 | } 369 | 370 | f = f + i; 371 | for (; i > 0; i--) { 372 | putChar('0' + char_buffer[i - 1]); 373 | } 374 | return f; 375 | 376 | } 377 | 378 | void SeeedGrayOLED::drawBitmap(const unsigned char* bitmaparray, int bytes) { 379 | if (Drive_IC == SSD1327) { 380 | char localAddressMode = addressingMode; 381 | if (addressingMode != HORIZONTAL_MODE) { 382 | //Bitmap is drawn in horizontal mode 383 | setHorizontalMode(); 384 | } 385 | 386 | for (int i = 0; i < bytes; i++) { 387 | 388 | for (int j = 0; j < 8; j = j + 2) { 389 | char c = 0x00; 390 | char bit1 = pgm_read_byte(&bitmaparray[i]) << j & 0x80; 391 | char bit2 = pgm_read_byte(&bitmaparray[i]) << (j + 1) & 0x80; 392 | 393 | // Each bit is changed to a nibble 394 | c |= (bit1) ? grayH : 0x00; 395 | // Each bit is changed to a nibble 396 | c |= (bit2) ? grayL : 0x00; 397 | sendData(c); 398 | } 399 | } 400 | if (localAddressMode == VERTICAL_MODE) { 401 | //If Vertical Mode was used earlier, restore it. 402 | setVerticalMode(); 403 | } 404 | } else if (Drive_IC == SH1107G) { 405 | int Row = 0, column_l = 0x00, column_h = 0x11; 406 | 407 | setHorizontalMode(); 408 | for (int i = 0; i < bytes; i++) { 409 | sendCommand(0xb0 + Row); 410 | sendCommand(column_l); 411 | sendCommand(column_h); 412 | 413 | byte bits = (byte)pgm_read_byte(&bitmaparray[i]); 414 | byte tmp = 0x00; 415 | for (int b = 0; b < 8; b++) { 416 | tmp |= ((bits >> (7 - b)) & 0x01) << b; 417 | } 418 | sendData(tmp); 419 | Row++; 420 | if (Row >= 12) { 421 | Row = 0; 422 | column_l++; 423 | if (column_l >= 16) { 424 | column_l = 0x00; 425 | column_h += 0x01; 426 | } 427 | } 428 | } 429 | } 430 | } 431 | 432 | void SeeedGrayOLED::setHorizontalScrollProperties(bool direction, unsigned char startRow, unsigned char endRow, 433 | unsigned char startColumn, unsigned char endColumn, unsigned char scrollSpeed) { 434 | /* 435 | Use the following defines for 'direction' : 436 | 437 | Scroll_Left 438 | Scroll_Right 439 | 440 | Use the following defines for 'scrollSpeed' : 441 | 442 | Scroll_2Frames 443 | Scroll_3Frames 444 | Scroll_4Frames 445 | Scroll_5Frames 446 | Scroll_25Frames 447 | Scroll_64Frames 448 | Scroll_128Frames 449 | Scroll_256Frames 450 | 451 | */ 452 | 453 | if (Scroll_Right == direction) { 454 | //Scroll Right 455 | sendCommand(0x27); 456 | } else { 457 | //Scroll Left 458 | sendCommand(0x26); 459 | } 460 | sendCommand(0x00); //Dummmy byte 461 | sendCommand(startRow); 462 | sendCommand(scrollSpeed); 463 | sendCommand(endRow); 464 | sendCommand(startColumn + 8); 465 | sendCommand(endColumn + 8); 466 | sendCommand(0x00); //Dummmy byte 467 | 468 | } 469 | 470 | void SeeedGrayOLED::activateScroll() { 471 | sendCommand(SeeedGrayOLED_Activate_Scroll_Cmd); 472 | } 473 | 474 | void SeeedGrayOLED::deactivateScroll() { 475 | sendCommand(SeeedGrayOLED_Dectivate_Scroll_Cmd); 476 | } 477 | 478 | void SeeedGrayOLED::setNormalDisplay() { 479 | sendCommand(SeeedGrayOLED_Normal_Display_Cmd); 480 | } 481 | 482 | void SeeedGrayOLED::setInverseDisplay() { 483 | sendCommand(SeeedGrayOLED_Inverse_Display_Cmd); 484 | } 485 | 486 | 487 | void SeeedGrayOLED::initSoftwareI2C(SoftwareI2C* w, int __sda, int __scl) { 488 | Wire = w; 489 | Wire->begin(__sda, __scl); 490 | } 491 | 492 | SeeedGrayOLED SeeedGrayOled; // Preinstantiate Objects 493 | 494 | -------------------------------------------------------------------------------- /SeeedGrayOLED.h: -------------------------------------------------------------------------------- 1 | /* 2 | SeeedGrayOLED.cpp 3 | SSD1327 Gray OLED Driver Library 4 | 5 | Copyright (c) 2011 seeed technology inc. 6 | Author : Visweswara R 7 | Create Time : Dec 2011 8 | Change Log : 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef SeeedGrayOLED_data_H 26 | #define SeeedGrayOLED_data_H 27 | 28 | // SeeedGrayOLED Instruction set addresses 29 | 30 | #include "Arduino.h" 31 | #include 32 | 33 | 34 | #define SH1107G 1 35 | #define SSD1327 2 36 | 37 | #define VERTICAL_MODE 01 38 | #define HORIZONTAL_MODE 02 39 | 40 | #define SeeedGrayOLED_Address 0x3c 41 | #define SeeedGrayOLED_Command_Mode 0x80 42 | #define SeeedGrayOLED_Data_Mode 0x40 43 | 44 | #define SeeedGrayOLED_Display_Off_Cmd 0xAE 45 | #define SeeedGrayOLED_Display_On_Cmd 0xAF 46 | 47 | #define SeeedGrayOLED_Normal_Display_Cmd 0xA4 48 | #define SeeedGrayOLED_Inverse_Display_Cmd 0xA7 49 | #define SeeedGrayOLED_Activate_Scroll_Cmd 0x2F 50 | #define SeeedGrayOLED_Dectivate_Scroll_Cmd 0x2E 51 | #define SeeedGrayOLED_Set_ContrastLevel_Cmd 0x81 52 | 53 | #define Scroll_Left 0x00 54 | #define Scroll_Right 0x01 55 | 56 | #define Scroll_2Frames 0x7 57 | #define Scroll_3Frames 0x4 58 | #define Scroll_4Frames 0x5 59 | #define Scroll_5Frames 0x0 60 | #define Scroll_25Frames 0x6 61 | #define Scroll_64Frames 0x1 62 | #define Scroll_128Frames 0x2 63 | #define Scroll_256Frames 0x3 64 | 65 | 66 | class SeeedGrayOLED { 67 | 68 | public: 69 | 70 | char addressingMode; 71 | 72 | void init(int IC); 73 | 74 | void setNormalDisplay(); 75 | void setInverseDisplay(); 76 | 77 | void sendCommand(unsigned char command); 78 | void sendData(unsigned char Data); 79 | void setGrayLevel(unsigned char grayLevel); 80 | 81 | void setVerticalMode(); 82 | void setHorizontalMode(); 83 | 84 | void setTextXY(unsigned char Row, unsigned char Column); 85 | void clearDisplay(); 86 | void setContrastLevel(unsigned char ContrastLevel); 87 | void putChar(unsigned char c); 88 | void putString(const char* String); 89 | unsigned char putNumber(long n); 90 | unsigned char putFloat(float floatNumber, unsigned char decimal); 91 | unsigned char putFloat(float floatNumber); 92 | 93 | void drawBitmap(const unsigned char* bitmaparray, int bytes); 94 | 95 | void setHorizontalScrollProperties(bool direction, unsigned char startRow, unsigned char endRow, 96 | unsigned char startColumn, unsigned char endColumn, unsigned char scrollSpeed); 97 | void activateScroll(); 98 | void deactivateScroll(); 99 | 100 | void initSoftwareI2C(SoftwareI2C* w, int __sda, int __scl); 101 | 102 | 103 | private: 104 | 105 | unsigned char grayH; 106 | unsigned char grayL; 107 | int Drive_IC; 108 | 109 | SoftwareI2C* Wire; 110 | 111 | 112 | }; 113 | 114 | extern SeeedGrayOLED SeeedGrayOled; // SeeedGrayOLED object 115 | 116 | #endif 117 | 118 | 119 | -------------------------------------------------------------------------------- /SoftwareI2C.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SoftwareI2C.cpp 3 | 2012 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | Author:Loovee 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | 25 | #include "SoftwareI2C.h" 26 | 27 | /************************************************************************************************* 28 | Function Name: begin 29 | Description: config IO 30 | Parameters: Sda: Scl: 31 | Return: none 32 | *************************************************************************************************/ 33 | void SoftwareI2C::begin(int Sda, int Scl) { 34 | pinSda = Sda; 35 | pinScl = Scl; 36 | 37 | pinMode(pinScl, OUTPUT); 38 | pinMode(pinSda, OUTPUT); 39 | sda_in_out = OUTPUT; 40 | digitalWrite(pinScl, HIGH); 41 | digitalWrite(pinSda, HIGH); 42 | } 43 | 44 | /************************************************************************************************* 45 | Function Name: sdaSet 46 | Description: set sda 47 | Parameters: ucDta: HIGH or LOW 48 | Return: none 49 | *************************************************************************************************/ 50 | void SoftwareI2C::sdaSet(uchar ucDta) { 51 | 52 | if (sda_in_out != OUTPUT) { 53 | sda_in_out = OUTPUT; 54 | pinMode(pinSda, OUTPUT); 55 | } 56 | digitalWrite(pinSda, ucDta); 57 | } 58 | 59 | /************************************************************************************************* 60 | Function Name: sclSet 61 | Description: set scl 62 | Parameters: ucDta: HIGH or LOW 63 | Return: none 64 | *************************************************************************************************/ 65 | void SoftwareI2C::sclSet(uchar ucDta) { 66 | digitalWrite(pinScl, ucDta); 67 | } 68 | 69 | 70 | /************************************************************************************************* 71 | Function Name: getAck 72 | Description: get ack 73 | Parameters: None 74 | Return: 0 – Nak; 1 – Ack 75 | *************************************************************************************************/ 76 | uchar SoftwareI2C::getAck(void) { 77 | sclSet(LOW); 78 | pinMode(pinSda, INPUT); 79 | sda_in_out = INPUT; 80 | 81 | sclSet(HIGH); 82 | unsigned long timer_t = micros(); 83 | while (1) { 84 | if (!digitalRead(pinSda)) { // get ack 85 | return GETACK; 86 | } 87 | 88 | if (micros() - timer_t > 100) { 89 | return GETNAK; 90 | } 91 | } 92 | } 93 | 94 | /************************************************************************************************* 95 | Function Name: sendStart 96 | Description: send start clock 97 | Parameters: None 98 | Return: None 99 | *************************************************************************************************/ 100 | void SoftwareI2C::sendStart(void) { 101 | sdaSet(LOW); 102 | } 103 | 104 | /************************************************************************************************* 105 | Function Name: setClockDivider 106 | Description: setup clock divider for spi bus 107 | Parameters: divider – clock divider 108 | Return: 0 – setup ok; 1 – setup failed 109 | *************************************************************************************************/ 110 | void SoftwareI2C::sendStop(void) { 111 | sclSet(LOW); 112 | sdaSet(LOW); 113 | sclSet(HIGH); 114 | sdaSet(HIGH); 115 | } 116 | 117 | /************************************************************************************************* 118 | Function Name: sendByte 119 | Description: send a byte 120 | Parameters: ucDta: data to send 121 | Return: None 122 | *************************************************************************************************/ 123 | void SoftwareI2C::sendByte(uchar ucDta) { 124 | for (int i = 0; i < 8; i++) { 125 | sclSet(LOW); 126 | sdaSet((ucDta & 0x80) != 0); 127 | ucDta <<= 0; 128 | sclSet(HIGH); 129 | sdaSet((ucDta & 0x80) != 0); 130 | ucDta <<= 1; 131 | } 132 | } 133 | 134 | /************************************************************************************************* 135 | Function Name: sendByteAck 136 | Description: send a byte and get ack signal 137 | Parameters: ucDta: data to send 138 | Return: 0: get nak 1: get ack 139 | *************************************************************************************************/ 140 | uchar SoftwareI2C::sendByteAck(uchar ucDta) { 141 | sendByte(ucDta); 142 | return getAck(); 143 | } 144 | 145 | /************************************************************************************************* 146 | Function Name: beginTransmission 147 | Description: send begin signal 148 | Parameters: divider – clock divider 149 | Return: 0: get nak 1: get ack 150 | *************************************************************************************************/ 151 | uchar SoftwareI2C::beginTransmission(uchar addr) { 152 | sendStart(); // start signal 153 | uchar ret = sendByteAck(addr << 1); // send write address and get ack 154 | //sclSet(LOW); 155 | return ret; 156 | } 157 | 158 | /************************************************************************************************* 159 | Function Name: endTransmission 160 | Description: send stop signal 161 | Parameters: None 162 | Return: None 163 | *************************************************************************************************/ 164 | uchar SoftwareI2C::endTransmission() { 165 | sendStop(); 166 | return 0; 167 | } 168 | 169 | /************************************************************************************************* 170 | Function Name: write 171 | Description: send a byte 172 | Parameters: dta: data to send 173 | Return: 0: get nak 1: get ack 174 | *************************************************************************************************/ 175 | uchar SoftwareI2C::write(uchar dta) { 176 | return sendByteAck(dta); 177 | } 178 | 179 | /************************************************************************************************* 180 | Function Name: write 181 | Description: write array 182 | Parameters: len - length of the array 183 | dta - array to be sent 184 | Return: 0: get nak 1: get ack 185 | *************************************************************************************************/ 186 | uchar SoftwareI2C::write(uchar len, uchar* dta) { 187 | for (int i = 0; i < len; i++) { 188 | 189 | if (GETACK != write(dta[i])) { 190 | return GETNAK; 191 | } 192 | } 193 | 194 | return GETACK; 195 | } 196 | 197 | /************************************************************************************************* 198 | Function Name: requestFrom 199 | Description: request data from slave 200 | Parameters: addr - address of slave 201 | len - length of request 202 | Return: 0: get nak 1: get ack 203 | *************************************************************************************************/ 204 | uchar SoftwareI2C::requestFrom(uchar addr, uchar len) { 205 | sendStart(); // start signal 206 | recv_len = len; 207 | uchar ret = sendByteAck((addr << 1) + 1); // send write address and get ack 208 | //sclSet(LOW); 209 | return ret; 210 | } 211 | 212 | /************************************************************************************************* 213 | Function Name: read 214 | Description: read a byte from i2c 215 | Parameters: None 216 | Return: data get 217 | *************************************************************************************************/ 218 | uchar SoftwareI2C::read() { 219 | if (!recv_len) { 220 | return 0; 221 | } 222 | 223 | uchar ucRt = 0; 224 | 225 | pinMode(pinSda, INPUT); 226 | sda_in_out = INPUT; 227 | 228 | for (int i = 0; i < 8; i++) { 229 | unsigned char ucBit; 230 | sclSet(LOW); 231 | sclSet(HIGH); 232 | ucBit = digitalRead(pinSda); 233 | ucRt = (ucRt << 1) + ucBit; 234 | } 235 | 236 | uchar dta = ucRt; 237 | recv_len--; 238 | 239 | if (recv_len > 0) { // send ACK 240 | sclSet(LOW); // sclSet(HIGH) 241 | sdaSet(LOW); // sdaSet(LOW) 242 | sclSet(HIGH); // sclSet(LOW) 243 | sclSet(LOW); 244 | } else { // send NAK 245 | sclSet(LOW); // sclSet(HIGH) 246 | sdaSet(HIGH); // sdaSet(LOW) 247 | sclSet(HIGH); // sclSet(LOW) 248 | sclSet(LOW); 249 | sendStop(); 250 | } 251 | return dta; 252 | } 253 | 254 | /********************************************************************************************************* 255 | END FILE 256 | *********************************************************************************************************/ -------------------------------------------------------------------------------- /SoftwareI2C.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoftwareI2C.h 3 | 2012 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-11-1 7 | 8 | This is a Software I2C Library, can act as I2c master mode. 9 | 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation; either 14 | version 2.1 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | #ifndef _SOFTWAREI2C_H_ 27 | #define _SOFTWAREI2C_H_ 28 | 29 | #define GETACK 1 // get ack 30 | #define GETNAK 0 // get nak 31 | 32 | #ifndef HIGH 33 | #define HIGH 1 34 | #endif 35 | #ifndef LOW 36 | #define LOW 0 37 | #endif 38 | 39 | #ifndef uchar 40 | #define uchar unsigned char 41 | #endif 42 | 43 | class SoftwareI2C { 44 | private: 45 | 46 | int pinSda; 47 | int pinScl; 48 | 49 | int recv_len; 50 | 51 | int sda_in_out; 52 | 53 | private: 54 | 55 | inline void sdaSet(uchar ucDta); 56 | inline void sclSet(uchar ucDta); 57 | 58 | inline void sendStart(void); 59 | inline void sendStop(void); 60 | inline uchar getAck(void); 61 | inline void sendByte(uchar ucDta); 62 | inline uchar sendByteAck(uchar ucDta); // send byte and get ack 63 | 64 | public: 65 | 66 | //SoftwareI2C(); 67 | void begin(int Sda, int Scl); 68 | uchar beginTransmission(uchar addr); 69 | uchar endTransmission(); 70 | 71 | uchar write(uchar dta); 72 | uchar write(uchar len, uchar* dta); 73 | uchar requestFrom(uchar addr, uchar len); 74 | uchar read(); 75 | uchar available() { 76 | return recv_len; 77 | } 78 | }; 79 | 80 | #endif 81 | /********************************************************************************************************* 82 | END FILE 83 | *********************************************************************************************************/ 84 | -------------------------------------------------------------------------------- /examples/OLED_Display/OLED_Display.ino: -------------------------------------------------------------------------------- 1 | #include "SoftwareI2C.h" 2 | SoftwareI2C WireS1; 3 | SoftwareI2C WireS2; 4 | 5 | 6 | #include "SeeedGrayOLED.h" 7 | #include 8 | 9 | SeeedGrayOLED SeeedGrayOled1; 10 | SeeedGrayOLED SeeedGrayOled2; 11 | 12 | 13 | void setup() { 14 | SeeedGrayOled1.initSoftwareI2C(&WireS1, 3, 2); // wire, sda, scl 15 | 16 | SeeedGrayOled1.init(SSD1327); 17 | SeeedGrayOled1.clearDisplay(); //Clear Display. 18 | SeeedGrayOled1.setNormalDisplay(); //Set Normal Display Mode 19 | SeeedGrayOled1.setVerticalMode(); // Set to vertical mode for displaying text 20 | 21 | 22 | for (char i = 0; i < 12 ; i++) { 23 | SeeedGrayOled1.setTextXY(i, 0); //set Cursor to ith line, 0th column 24 | SeeedGrayOled1.setGrayLevel(i); //Set Grayscale level. Any number between 0 - 15. 25 | SeeedGrayOled1.putString("11111111"); //Print Hello World 26 | } 27 | 28 | 29 | SeeedGrayOled2.initSoftwareI2C(&WireS2, 5, 4); // wire, sda, scl 30 | 31 | SeeedGrayOled2.init(SSD1327); //initialize SEEED OLED display 32 | SeeedGrayOled2.clearDisplay(); //Clear Display. 33 | SeeedGrayOled2.setNormalDisplay(); //Set Normal Display Mode 34 | SeeedGrayOled2.setVerticalMode(); // Set to vertical mode for displaying text 35 | 36 | for (char i = 0; i < 12 ; i++) { 37 | SeeedGrayOled2.setTextXY(i, 0); //set Cursor to ith line, 0th column 38 | SeeedGrayOled2.setGrayLevel(i); //Set Grayscale level. Any number between 0 - 15. 39 | SeeedGrayOled2.putString("00000000"); //Print Hello World 40 | } 41 | 42 | 43 | } 44 | 45 | void loop() { 46 | 47 | } 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /examples/SoftwareI2C_Scan/SoftwareI2C_Scan.ino: -------------------------------------------------------------------------------- 1 | // i2c scan 2 | #include "SoftwareI2C.h" 3 | 4 | SoftwareI2C softwarei2c; 5 | 6 | void setup() { 7 | Serial.begin(115200); 8 | softwarei2c.begin(3, 2); // sda, scl 9 | Serial.println("begin to scan..."); 10 | } 11 | 12 | void loop() { 13 | for (unsigned char i = 1; i <= 127; i++) { 14 | if (softwarei2c.beginTransmission(i)) { 15 | Serial.print("0x"); 16 | Serial.println(i, HEX); 17 | 18 | while (1); 19 | } 20 | softwarei2c.endTransmission(); 21 | } 22 | 23 | Serial.println("find nothing"); 24 | while (1); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Seeed OLED 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | addressingMode KEYWORD1 10 | SeeedGrayOled KEYWORD1 11 | 12 | ####################################### 13 | # Methods and Functions (KEYWORD2) 14 | ####################################### 15 | 16 | init KEYWORD1 17 | setNormalDisplay KEYWORD1 18 | setInverseDisplay KEYWORD1 19 | sendCommand KEYWORD1 20 | setGrayLevel KEYWORD1 21 | setVerticalMode KEYWORD1 22 | setHorizontalMode KEYWORD1 23 | setGrayLevel KEYWORD1 24 | setTextXY KEYWORD1 25 | clearDisplay KEYWORD1 26 | setContrastLevel KEYWORD1 27 | putChar KEYWORD1 28 | putString KEYWORD1 29 | putNumber KEYWORD1 30 | drawBitmap KEYWORD1 31 | setHorizontalScrollProperties KEYWORD1 32 | activateScroll KEYWORD1 33 | deactivateScroll KEYWORD1 34 | 35 | 36 | ####################################### 37 | # Constants (LITERAL1) 38 | ####################################### 39 | 40 | Scroll_Left LITERAL1 41 | Scroll_Right LITERAL1 42 | 43 | Scroll_2Frames LITERAL1 44 | Scroll_3Frames LITERAL1 45 | Scroll_4Frames LITERAL1 46 | Scroll_5Frames LITERAL1 47 | Scroll_25Frames LITERAL1 48 | Scroll_64Frames LITERAL1 49 | Scroll_128Frames LITERAL1 50 | Scroll_256Frames LITERAL1 51 | 52 | ####################################### 53 | # Instances (KEYWORD2) 54 | ####################################### 55 | 56 | SeeedGrayOLED KEYWORD2 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Arduino Software I2C 2 | version=1.0.0 3 | author=Seeed Studio 4 | maintainer=Seeed Studio 5 | sentence=Arduino library to use Software I2C. 6 | paragraph=Arduino library to use Software I2C. 7 | category=Communication 8 | url=https://github.com/Seeed-Studio/Arduino_Software_I2C 9 | architectures=* --------------------------------------------------------------------------------