{"id":15107610,"url":"https://github.com/pharo-iot/pharothings","last_synced_at":"2025-04-06T03:11:49.870Z","repository":{"id":75153917,"uuid":"98889267","full_name":"pharo-iot/PharoThings","owner":"pharo-iot","description":"Live programming platform for IoT projects based on Pharo","archived":false,"fork":false,"pushed_at":"2025-03-15T08:38:58.000Z","size":1129,"stargazers_count":91,"open_issues_count":3,"forks_count":16,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-06T03:11:45.962Z","etag":null,"topics":["arduino","ide","iot-platform","live-programming","pharo","pharothings","raspberry-pi","telepharo"],"latest_commit_sha":null,"homepage":"","language":"Smalltalk","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pharo-iot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-07-31T13:01:06.000Z","updated_at":"2025-03-15T08:39:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"d73dce0a-34c2-4362-821a-78575f1103c4","html_url":"https://github.com/pharo-iot/PharoThings","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pharo-iot%2FPharoThings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pharo-iot%2FPharoThings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pharo-iot%2FPharoThings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pharo-iot%2FPharoThings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pharo-iot","download_url":"https://codeload.github.com/pharo-iot/PharoThings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247427012,"owners_count":20937214,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","ide","iot-platform","live-programming","pharo","pharothings","raspberry-pi","telepharo"],"created_at":"2024-09-25T21:40:28.998Z","updated_at":"2025-04-06T03:11:49.843Z","avatar_url":"https://github.com/pharo-iot.png","language":"Smalltalk","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PharoThings (archived)\n[![Build Status](https://travis-ci.org/pharo-iot/PharoThings.svg?branch=master)](https://travis-ci.org/pharo-iot/PharoThings)\n\nThis project is right now on sleeping mode. We do not have the resources to maintain it and evolve it. \n\n\nLive programming platform for IoT projects based on [Pharo](http://pharo.org).\nIt includes:\n- development tools to lively program, explore and debug remote boards (based on [TelePharo](https://github.com/dionisiydk/TelePharo))\n- board modeling library which simplifies board configuration\n\n    - Raspberry driven by [WiringPi library](http://wiringpi.com)\n    - Arduino driven by [Firmata](https://github.com/firmata/arduino), soon\n    - Beaglebone, soon\n\nNow PharoThings is in beta stage together with documentation and videos. It will be improved constantly.\n\n## PharoThings Booklet\n\nYou can access the **PharoThings Booklet** with many examples and lessons from the official repository:\n\nhttps://github.com/SquareBracketAssociates/Booklet-APharoThingsTutorial\n\n## Installation on Raspberry\n\n1) Download Pharo 6 and install the server part of PharoThings:\n```Smalltalk\nMetacello new\n  baseline: 'PharoThings';\n  repository: 'github://pharo-iot/PharoThings/src';\n  load: #(RemoteDevServer Raspberry).\n```\nThen configure image to disable slow browser plugins (instead remote browser will be much slower):\n```Smalltalk\nClySystemEnvironmentPlugin disableSlowPlugins\n```\nAt the end save the image.\n\n2) Download ArmVM http://files.pharo.org/vm/pharo-spur32/linux/armv6/latest.zip. It will run Pharo on your board\n\n3) Copy saved image, changes, sources and ArmVM files into your Raspberry (files should be in same directory)\n\n4) Install [WiringPi library](http://wiringpi.com) in Raspberry\n\nIf you use the latest desktop version of Raspbian skip this step (WiringPi is included). The Light Raspbian version is required manual installation of WiringPi.\n\nPharoThings uses WiringPi to control Raspberry pins. You need install it in your board. There is a convenient prebuilt package [here](https://github.com/hamishcunningham/wiringpi/tree/master/package/2.13/unstable). Follow [install](https://github.com/hamishcunningham/wiringpi/blob/master/INSTALL) instructions or do it your own way.\n\nYou can test the WiringPi library in terminal. More information [here](http://wiringpi.com/the-gpio-utility/)\n```\ngpio readall\n```\n\nIf you receive any error, you should update the WiringPi library:\n```\ncd /tmp\nwget https://unicorn.drogon.net/wiringpi-2.46-1.deb\nsudo dpkg -i wiringpi-2.46-1.deb\n```\n\n5) Start Pharo on Raspberry with the server option:\n```bash\npharo --headless Server.image  remotePharo --startServerOnPort=40423\n```\nIt will listen for remote IDE connections on port 40423.\n\nYou can also prepare an image with a running server. Evaluate the following code in a playground and save the image:\n```Smalltalk\nTlpRemoteUIManager registerOnPort: 40423\n```\nIn that case command line option --startServerOnPort is not needed. Just start Pharo with --no-quit option:\n```bash\npharo --headless Server.image  --no-quit\n```\n\n## Connecting to the board\nInstall the client part of PharoThings in the development (client) Pharo image:\n```Smalltalk\nMetacello new\n  baseline: 'PharoThings';\n  repository: 'github://pharo-iot/PharoThings/src';\n  load: 'RemoteDev'\n```\nConnect to remote Pharo running on Raspberry using playground:\n```Smalltalk\nremotePharo := TlpRemoteIDE connectTo: (TCPAddress ip: #[193 51 236 167] port: 40423)\n```\nNotice that you should know the IP address of your Raspberry and port where running Pharo is waiting for remote IDE connection. In this example we used port 40423.\n\nWith the remotePharo instance you can open many different tools to develop and explore remote Pharo images. It is part of [TelePharo project](https://github.com/dionisiydk/TelePharo). Look at it for details. \n\nHere we are using specialized Raspberry tools. They require auto refresh feature of inspector which is not enabled by default in Pharo 6. To activate it evaluate:\n```Smalltalk\nGTInspector enableStepRefresh\n```\n\n## Inspecting the board\nTo inspect the board you need to know the concrete model of your Raspberry. Currently only model B is supported (with revision 1 and 2). But you can play with the following code on other boards too to get a feeling of this project. In that case pins could point to the wrong physical pins of your board. But tools will not break and will show the same working UI. Also you are always able to work with a board by using the low level library (like WiringPi) using the powerfull remote tools from [TelePharo](https://github.com/dionisiydk/TelePharo).\n\nBy the way, the implementation of a specific Raspberry model is very simple task (will be explained later). Feel free to implement support for it and contribute the code to the project. \n\nSo for your board model you need to choose an appropriate board class. For Raspberry it will be one of the RpiBoard subclasses.\nWith the choosen class evaluate the following code to open an inspector:\n```Smalltalk\nremoteBoard := remotePharo evaluate: [ RpiBoardBRev1 current].\nremoteBoard inspect\n```\nIn this case we work with Raspberry model B revision 1.\n\n## The board inspector\n\n![](doc/images/RaspBoardInspector.png)\n\nThe board inspector provides a scheme of pins similar to Raspberry Pi docs.\nBut here it is a live tool which represents the current pins state. \n\nIn the picture the board is shown with two configured pins: gpio3 and gpio4 which are connected to physical button and led accordingly.\n\nDigital pins are shown with green/red icons which represent high/low (1/0) values. In case of output pins you are able to click on the icon to toggle the value. Icons are updated according to pin value changes. If you click on physical button on your board the inspector will show the updated pin state by changing its icon color.\n\nThe evaluation pane in the bottom of the inspector provides bindings to gpio pins which you can script by #doIt/printIt commands. The example shows expressions which were used to configure a button and led.\n\nFor the led we first introduced named variable #led which we assigned to gpio4 pin instance:\n```Smalltalk\nled := gpio4\n```\nThen we configured the pin to be in digital output mode and set the value:\n```\nled beDigitalOutput.\nled value: 1\n```\nIt turned the led on.\n\nFor button we did the same but with digital input mode and extra resistor configuration:\n```Smalltalk\nbutton := gpio3.\nbutton beDigitalInput. \"button\"\nbutton enablePullDownResister.\n```\nYou can notice that gpio variables are not just numbers/ids. PharoThings models boards with first class pins. They are real objects with behaviour. For example you can ask pin to toggle a value:\n```\nled toggleDigitalValue\n```\nOr ask a pin for current value if you want to check it:\n```Smalltalk\nled value.\nbutton value\n```\nThe following demo shows an inspector in live:\n\n[![](https://img.youtube.com/vi/0H9of7PQet0/0.jpg)](https://www.youtube.com/watch?v=0H9of7PQet0)\n\n## The device model\nPin scripting is cool and powerful feature but when you need real logic for your pins it is better to put it in objects.\n\nPharoThings provides simple high level model of devices which you can use to implement complex interaction with your board.\n\nFor example with button device you can subscribe on #press/release events:\n```Smalltalk\nbutton := board installDevice: (PotButton named: 'button' fromPowerTo: gpio3).\nbutton when: PotButtonReleased send: #toggleDigitalValue to: led.\n```\nIt will connect the physical button to the led as a switch device which turns the led on and off on button click. \n\nDevices incapsulate pin configuration logic. You don't need to configure an input pin manually when you create a button instance. Just install the device and the pin will work. \n\nNotice that in example the physical button is connected to the gpio pin from power. That is why we use \"named:fromPowerTo:\" selector when we create a button instance. But a button can be connected another way, too. And in that case we would use the selector #named:fromGroundTo:. It is important to create an instance in the same way as it is connected in the real world because otherwise the button will not work. The reason will be explained later. This logic is hidden by PotButton class and users do not need to think about it.\n\nNow to toggle the led we still use a script inside inspector. We can replace it with another device PotSwitch:\n```Smalltalk\nbutton unsubscribe: led. \"disable previous script behaviour\"\nboard installDevice: (PotSwitch named: 'led switch' for: gpio4 using: button).\n```\n(first line is required because instead toggle will be performed twice which will not change anything)\n\nThe board inspector provides extra tab to manage installed devices:\n\n![](doc/images/RaspBoardDevicesInspector.png)\n\nThis tab shows the live state of devices. You can click on output pins to modify values.\n\nFrom the context menu you can disable and remove devices. And you can also browse the implementation.\n\nThe following demo shows devices in live:\n\n[![](https://img.youtube.com/vi/ezfjditHjq4/0.jpg)](https://www.youtube.com/watch?v=ezfjditHjq4)\n\n## Implementing new devices\n\nThis topic will be described in details later. Now look at following demo as a simple example how develop and debug the live Raspberry remotely:\n\n[![](https://img.youtube.com/vi/5i0tsgFtlOg/0.jpg)](https://www.youtube.com/watch?v=5i0tsgFtlOg)\n\n## Persist board changes\nIf the board is configured you can save the remote image to persist board changes:\n```Smalltalk\nremotePharo saveImage\n```\nWhen you restart the image board pins will restore the saved state and installed devices will continue working.\n\nFor example, try to save the board with an led on. Then turn the led of and restart the Pharo. When Pharo will start, the led will be on (because the image was saved in that state).\n\nAll processes running in Pharo are also persistent. For example from the inspector you can connect the button pin to the led with a simple process:\n```Smalltalk\n[ [100 milliSeconds wait. \n\tled value: (button value=1) asBit\n\t\t] repeat\t\n\t ] forkNamed: 'button process'.\n```\nIt will turn the led on when the button is pressed. \n\nNow if you save the image this process will continue working after Pharo restart.\n\nAll videos above show persistence in live.\n\n## I2C devices\nTo interract with I2C device the I2C connection must be opened:\n```Smalltalk\ni2cConnection := board connectToI2CDevice: addressInt\n```\nThe argument is address/id of target device which is physically connected to the board.\nFor Rassperry board the result is an instance of WiringPiI2CConnection. It provides i/o functions which are available in WiringPi library. For example:\n```Smalltalk\ni2cConnection read8BitsAt: 16rA1.\ni2cConnection write8BitsAt: 16rF2 data: 16r01.\t\n```\nIn future the connection interface will be improved to be common for different kind of boards.\n\nTo implement model of I2C device the subclass of PotI2CDevice should be implemented. PotI2CDevice provides prepared i2cConnection.\nSubclases should implement device initialization in connection method. And they should provide required methods to communicate with target devices.\n\n### MCP9808\nPotMCP9808Device implements model of temperature sensor MCP9808.\n\nThe code for initialization and sensors reading is copied from [Python example](https://github.com/ControlEverythingCommunity/MCP9808/blob/master/Python/MCP9808.py).\n\t\nThe method #readTemperature returns the value in Celsius\n\nTo use:\n- board inspector\n```sensor := board installDevice: PotMCP9808Device new.```\n\n- playground. change the board model  to your board\n```sensor := (RpiBoard3B current) installDevice: PotMCP9808Device new.```\n\n### BME280\nPotBME280Device implements temperature/pressure/humidity sensor BME280.\n\nThe code for initialization and sensors reading is copied from [Python example](https://github.com/ControlEverythingCommunity/BME280/blob/master/Python/BME280.py).\n\t\nThe method #readParameters returns three values: Celsius, hPa, humidity percents.\nIn addition there is method #readTemperature to get single value.\n\nTo use:\n- board inspector\n```sensor := board installDevice: PotBME280Device new.```\n\n- board playground. change the board model  to your board\n```sensor := (RpiBoard3B current) installDevice: PotBME280Device new.```\n\n### ADXL345\nPotADXL345Device implements accelerometer ADXL345.\n\nThe code for initialization and sensors reading is copied from [sunfolder example](https://www.sunfounder.com/learn/Super_Kit_V2_for_RaspberryPi/lesson-14-adxl345-super-kit-for-raspberrypi.html).\n\t\nThe method #readCoordinates returns three values array.\n\nTo use:\n- board inspector\nsensor := board installDevice: PotADXL345Device new.\n\n- playground. change the board model  to your board\nsensor := (RpiBoard3B current) installDevice: PotADXL345Device new.\n\n### HCSR-04 ultrasonic\nPotHCSR04Device implements HCSR-04 ultrasonic sensor\n\nTo use:\n- board inspector\n```ultrasonic := board installDevice: (PotHCSR04Device triggerPin: 17 gpio echoPin: 27 gpio).```\n\n- playground, change the board model to your board\n```ultrasonic := (RpiBoard3B current) installDevice: (PotHCSR04Device triggerPin: 17 gpio echoPin: 27 gpio).```\n\nTo read the distance use one of the method below. \n```\nreadDistance. \"It will return a number\".\nprintDistance. \"It will return a string\".\n```\nReboot the sensor:\n\n```\nrebootSensor.\n```\n\n### HD44780 LCD chipset\nPotLCDHD44780 implements LCD controller to all devices using this chipset. \n\nPotLCD1602Device and PotLCD1602DeviceI2C implements LCD1602 display using GPIOs and I2C interface.\n\nTo use:\n- board inspector\n```lcd := board installDevice: PotLCD1602Device new.```\nor to I2C\n```lcd := board installDevice: PotLCD1602DeviceI2C new.```\n\n- playground. change the board model  to your board\n```lcd := (RpiBoard3B current) installDevice: PotLCD1602Device new.```\nor to I2C\n```lcd := (RpiBoard3B current) installDevice: PotLCD1602DeviceI2C new.```\n\nAPI:\n```\nshowMessage: 'Hello\nPharo IoT'.\nclearDisplay.\ndisableBlinkCursor.\ndisableDisplay.\ndisableUnderlineCursor. \nenableBlinkCursor.\nenableDisplay.\nenableUnderlineCursor.\nmoveCursorLeft. \nmoveCursorRight.\nreturnHome.\nsetCursorAtRow:2.\nsetCursorAtRow:1 column:1.\nsetLeftAutoScroll.\nsetLeftToRight.\nsetRightAutoScroll.\nsetRightToLeft.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpharo-iot%2Fpharothings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpharo-iot%2Fpharothings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpharo-iot%2Fpharothings/lists"}