-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Double check and update all I2C examples
- Loading branch information
Showing
24 changed files
with
124 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
# | ||
# Example using a D3231 real-time-clock over I2C. Sets the time and reads it | ||
# back every 5 seconds. | ||
# D3231 real-time-clock over I2C. Set time and read back every 5 seconds. | ||
# | ||
require 'bundler/setup' | ||
require 'denko' | ||
|
||
board = Denko::Board.new(Denko::Connection::Serial.new) | ||
# Board's hardware I2C interface on predetermined pins. | ||
bus = Denko::I2C::Bus.new(board: board) # address: 0x68 default | ||
i2c = Denko::I2C::Bus.new(board: board) # address: 0x68 default | ||
|
||
# Tell the bus to search for devices. | ||
bus.search | ||
i2c.search | ||
|
||
# Show the found devices. | ||
puts "No I2C devices connected!" if bus.found_devices.empty? | ||
bus.found_devices.each do |address| | ||
puts "I2C device connected with address: 0x#{address.to_s(16)}" | ||
if i2c.found_devices.empty? | ||
puts "No I2C devices connected!" | ||
return | ||
end | ||
|
||
# 0x68 or 140 is the I2C address for most real time clocks. | ||
unless (bus.found_devices.include? 0x68) | ||
puts "No real time clock found!" unless bus.found_devices.empty? | ||
else | ||
puts; puts "Using real time clock at address 0x68"; puts | ||
rtc = Denko::RTC::DS3231.new(bus: bus, address: 0x68) | ||
rtc.time = Time.now | ||
# 0x68 is the I2C address for most real time clocks. | ||
unless (i2c.found_devices.include? 0x68) | ||
puts "DS3231 real time clock not found!" | ||
return | ||
end | ||
|
||
puts "Using DS3231 RTC at address 0x68"; puts | ||
rtc = Denko::RTC::DS3231.new(bus: i2c, address: 0x68) | ||
rtc.time = Time.now | ||
|
||
5.times do | ||
puts rtc.time | ||
sleep 5 | ||
end | ||
5.times do | ||
puts rtc.time | ||
sleep 5 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.