Skip to content

Commit

Permalink
Merge pull request #34 from pharo-iot/dev
Browse files Browse the repository at this point in the history
Merge the Dev branch in the Master branch
  • Loading branch information
oliveiraallex committed Jul 24, 2019
2 parents 89bca2e + f203dd8 commit 98b891d
Show file tree
Hide file tree
Showing 380 changed files with 1,542 additions and 311 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ language: smalltalk
sudo: false
os:
- linux
smalltalk_edge:
source: hpi-swa/smalltalkCI
branch: dev
smalltalk:
- Pharo-6.0
- Pharo-7.0
- Pharo32-8.0
- Pharo64-8.0
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ devices
#'PharoThings-Devices-Button' -> #().
#'PharoThings-Devices-Switch' -> #(#'PharoThings-Devices-Button').
#'PharoThings-Devices-WaterAlarm' -> #().

#'PharoThings-Devices-HCSR04' -> #().
#'PharoThings-Devices-ADXL345' -> #(#'PharoThings-Devices-I2C').
#'PharoThings-Devices-MCP9808' -> #(#'PharoThings-Devices-I2C').
#'PharoThings-Devices-BME280' -> #(#'PharoThings-Devices-I2C').
#'PharoThings-Devices-HD44780' -> #(#'PharoThings-Devices-I2C')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
printing
printHumidity
^self readHumidity printShowingDecimalPlaces: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
printing
printPressure
^self readPressure printShowingDecimalPlaces: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
printing
printTemperature
^self readTemperature printShowingDecimalPlaces: 1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
controlling
readHumidity
^self readParameters last
^self readParameters last round: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
controlling
readPressure
^self readParameters second round: 1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
controlling
readTemperature
^self readParameters first
^self readParameters first round: 1
5 changes: 5 additions & 0 deletions src/PharoThings-Devices-HCSR04.package/.filetree
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"separateMethodMetaAndSource" : false,
"noMethodMetaData" : true,
"useCypressPropertiesFile" : true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
I'm a class to control the ultrasonic HCSR-04 sensors.
You can use many ultrasonic sensors at the same time. Just create a new instance with different gpios.

How Does it Work?
The ultrasonic sensor uses sonar to determine the distance to an object. Here’s what happens:
- The transmitter (trig pin) sends a signal: a high-frequency sound.
- When the signal finds an object, it is reflected and
- the transmitter (echo pin) receives it.
The time between the transmission and reception of the signal allows us to calculate the distance to an object. This is possible because we know the sound’s velocity in the air.

To use:
- inspector
ultrasonic := board installDevice: (PotHCSR04Device triggerPin: 11 gpioHeader echoPin: 13 gpioHeader).

- playground, change the board model to your board
ultrasonic := (RpiBoard3B current) installDevice: (PotHCSR04Device triggerPin: 11 gpioHeader echoPin: 13 gpioHeader).

You can name the object using
name: 'Left sensor'.

To read the distance use one of the method below.

readDistance. "It will return a number".
printDistance. "It will return a string".

Some of my sensors brothers uses only 1 GPIO to send and read the ultrasonic pulse.
You can set it using the follow method. It will configure trigger and echo pin at the same GPIO:

ultrasonic := (RpiBoard3B current) installDevice: (PotHCSR04Device signalPin: 13 gpioHeader).

Sometimes I can freeze. You can reboot me using

rebootSensor.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
settings
signalPin: aGPIOPin
^self new
triggerPin: aGPIOPin;
echoPin: aGPIOPin;
yourself
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
settings
triggerPin: aGPIOPin1 echoPin: aGPIOPin2
^self new
triggerPin: aGPIOPin1;
echoPin: aGPIOPin2;
yourself
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
commands
calculateDistance: aTravelTimeNumber
"distance = (traveltime/2) x speed of sound
The speed of sound is: 343m/s
We need to divide the traveltime by 2 because we have to take into account that the wave was sent, hit the object, and then returned back to the sensor."
^ (aTravelTimeNumber * 34300 / 2 / 1000000) asFloat round: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialization
connect
^ nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
echoPin: anObject
^ echoPin := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
echoPin
^ echoPin
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialization
isConfigured
^ triggerPin notNil
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialization
isConnected
^ board notNil
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
peripherals
^ {triggerPin. echoPin}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
commands
printDistance
^ self readDistance printShowingDecimalPlaces: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
commands
readDistance
"Send a pulse, read the travel time of pulse and return the distance in cm"
| travelTime semaphore |
semaphore := Semaphore new.
[ self sendPulse.
travelTime := self readPinStateDuration.
semaphore signal ] fork.
semaphore
wait: 100 milliSeconds
onCompletion: [ ^ self calculateDistance: travelTime ]
onTimeout: [ self rebootSensor. ^ -1 ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
controlling
readPinStateDuration
"The echo PIN will be active for the same length of time between sending and receiving the signal. It will be activated after receiving the sound wave back."
| pulseStart pulseEnd |
echoPin beDigitalInput; enablePullDownResister.
[ echoPin value == 0 ] whileTrue: [ pulseStart := Time primUTCMicrosecondsClock ].
[ echoPin value == 1 ] whileTrue: [ pulseEnd := Time primUTCMicrosecondsClock ].
^ pulseEnd - pulseStart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
commands
rebootSensor
"Reset the pins when the sensor freeze"
echoPin beDigitalOutput; value: 1.
1 milliSeconds wait.
echoPin value: 0; beDigitalInput; enablePullDownResister.
triggerPin beDigitalOutput; value: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
controlling
sendPulse
triggerPin beDigitalOutput; value: 0; value: 1.
1 milliSeconds wait.
triggerPin value: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
triggerPin: anObject
triggerPin := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
triggerPin
^ triggerPin
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"commentStamp" : "AllexOliveira 7/19/2019 15:34",
"super" : "PotDevice",
"category" : "PharoThings-Devices-HCSR04",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"triggerPin",
"echoPin"
],
"name" : "PotHCSR04Device",
"type" : "normal"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SystemOrganization addCategory: #'PharoThings-Devices-HCSR04'!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(name 'PharoThings-Devices-HCSR04')
1 change: 1 addition & 0 deletions src/PharoThings-Devices-HCSR04.package/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ }
5 changes: 5 additions & 0 deletions src/PharoThings-Devices-HD44780.package/.filetree
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"separateMethodMetaAndSource" : false,
"noMethodMetaData" : true,
"useCypressPropertiesFile" : true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
initialization
initialize
super initialize.
displayControl := self hexArrayBitOrToNumber:{LCD_DISPLAYON.LCD_CURSOROFF.LCD_BLINKOFF}.
displayFunction := self hexArrayBitOrToNumber:{LCD_4BITMODE.LCD_1LINE.LCD_2LINE.LCD_5x8DOTS}.
displayMode := self hexArrayBitOrToNumber:{LCD_ENTRYLEFT.LCD_ENTRYSHIFTDECREMENT}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"commentStamp" : "",
"super" : "PotLCDHD44780Gpio",
"category" : "PharoThings-Devices-HD44780",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "PotLCD1602Device",
"type" : "normal"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
initialization
initialize
super initialize.
displayControl := self hexArrayBitOrToNumber: {LCD_DISPLAYON}.
displayFunction := self hexArrayBitOrToNumber: {LCD_4BITMODE. LCD_2LINE. LCD_5x8DOTS}.
displayMode := self hexArrayBitOrToNumber: {LCD_ENTRYLEFT}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"commentStamp" : "",
"super" : "PotLCDHD44780I2C",
"category" : "PharoThings-Devices-HD44780",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "PotLCD1602DeviceI2C",
"type" : "normal"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
I'm a class to control the HD44780 chipset based devices.

My code was based in python code from Adafruit:

https://github.com/adafruit/Adafruit_Python_CharLCD/blob/master/Adafruit_CharLCD/Adafruit_CharLCD.py

To use:
(inspector)
lcd := board installDevice: PotLCD1602Device new.
or to I2C
lcd := board installDevice: PotLCD1602DeviceI2C new.

(playground. change the board model to your board)
lcd := (RpiBoard3B current) installDevice: PotLCD1602Device new.
or to I2C
lcd := (RpiBoard3B current) installDevice: PotLCD1602DeviceI2C new.

Sent a message to LCD display:
lcd showMessage:
'your text first row
your text second row'

Clear LCD display:
lcd clearDisplay

API:
lcd showMessage: 'Hello
Pharo IoT'.
lcd clearDisplay.
lcd disableBlinkCursor.
lcd disableDisplay.
lcd disableUnderlineCursor.
lcd enableBlinkCursor.
lcd enableDisplay.
lcd enableUnderlineCursor.
lcd moveCursorLeft.
lcd moveCursorRight.
lcd returnHome.
lcd setCursorAtRow:2.
lcd setCursorAtRow:1 column:1.
lcd setLeftAutoScroll.
lcd setLeftToRight.
lcd setRightAutoScroll.
lcd setRightToLeft.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testing
isAbstract
^self = PotLCDHD44780
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
commands
clearDisplay
self writeCommand: LCD_CLEARDISPLAY.
3 milliSeconds wait
"waiting to clear the display"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialization
connect
self subclassResponsibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
commands
disableBlinkCursor
self
setDisplayControl: (displayControl bitAnd: LCD_BLINKON bitInvert)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
commands
disableDisplay
self
setDisplayControl: (displayControl bitAnd: LCD_DISPLAYON bitInvert)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
commands
disableUnderlineCursor
self
setDisplayControl: (displayControl bitAnd: LCD_CURSORON bitInvert)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
commands
enableBlinkCursor
self
setDisplayControl: (displayControl bitOr: LCD_BLINKON)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
commands
enableDisplay
self
setDisplayControl: (displayControl bitOr: LCD_DISPLAYON)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
commands
enableUnderlineCursor
self
setDisplayControl: (displayControl bitOr: LCD_CURSORON)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
initialization
hexArrayBitOrToNumber: anArray
^ anArray inject: 0 into: [:each : hex | hex bitOr: each]
"hexArrayToNumber: #(16r06 16r01 16r08) ^16r0F"
Loading

0 comments on commit 98b891d

Please sign in to comment.