Powered by Blogger.

Sunday, January 1, 2017

Lesson 16: Playground-Arduino Blocks

Screenshot_54
Arduino blocks set can be used with Arduino Mega or Arduino Uno with the help of MagicWiFiShield . Following blocks are available,
  • Digital in
  • Analog In
  • Digital Out
  • PWM (Analog Out)
  • Servo
  • Serial In
  • Serial Out
  • DS1820
  • LCD16x2Out

This block set enables you to control individual pins of the Arduino from the playground. The functionality of each block is described below:
How to configure Arduino
To work with arduino blocks you need to upload following sketch to ardunio.Then connect MagicWifiShield to the arduino.
How to attach a device
Every block has a property called Device ID where you need to specify to which device this block belongs to. This is important because you will be working with multiple devices in a typical IoT project. To control a device (eg: Arduino) via the playground you need to add the device as in Lesson 3 and if you have already done so, attach it to the playground according to the description below.
To attach a device ID for the first time, select 'Add new arduino-board' and click the edit button as shown below. If you have already added the device as in Lesson 3, it will be visible to you in the dropdown and you can select the device from there.

Screenshot_55
In the next dialog click the search button which will display all your added devices. Select the device you want to add and click 'Add'. Once you have added a device you can select it from the dropdown in the respective node.
Screenshot_56
Screenshot_57
Every blue color block have property called Pin which will identify specific pin of the Arduino.

1. Digital In


FotorCreated_thumb4
This block will read Input status of a pin. Block need to triggered to get input status. Any input will serve as a trigger. Inject node can be used for this purpose.Input status can be passed to a another block or viewed on the debug window.
  • Configuration:
    • Pin: pin number of the digital pin to read (Required)
    • Name: Any name desired
  • Input
    • Any input. Used as a trigger
  • Output
    • Value of the pin as 1 or 0 in the following format and the pin number as the topic
      • eg: {"payload": 1 , "topic": "2"}
[{"id":"2992d39.d0af72c","type":"inject","z":"ce37cda6.eebb4","name":"","topic":"","payload":"","payloadType":"none","repeat":"1","crontab":"","once":false,"x":458.09942626953125,"y":809.54541015625,"wires":[["390fb40b.32758c"]]},{"id":"390fb40b.32758c","type":"Digital In","z":"ce37cda6.eebb4","name":"","pin":"13","arduino":"","x":618.9545440673828,"y":808.2301073626056,"wires":[[]]},{"id":"b5081d9d.4c3fc","type":"comment","z":"ce37cda6.eebb4","name":"Set MagicWiFiShield ID","info":"","x":622.9601898193359,"y":756.4090270996094,"wires":[]}]

2. Digital Out


FotorCreated2_thumb1
This block is used to set a digital output pin to 1 or 0 based on the input. An input of 1 or true will make the configured pin go HIGH and vice versa
  • Configuration
    • Pin: pin number of the Digital pin to write to
    • Name: Any name desired
  • Input
    • Value to be written to the pin. Accepts 1 (true) or 0 (false)
      • eg: {"payload": 1}
[{"id":"b5081d9d.4c3fc","type":"comment","z":"ce37cda6.eebb4","name":"Set MagicWiFiShield ID","info":"","x":622.9601898193359,"y":756.4090270996094,"wires":[]},{"id":"540c63cd.4951dc","type":"inject","z":"ce37cda6.eebb4","name":"","topic":"","payload":"1","payloadType":"string","repeat":"1","crontab":"","once":false,"x":387.09942626953125,"y":771.54541015625,"wires":[["ec667bf9.daf2f8"]]},{"id":"988aa6e.a7f1658","type":"inject","z":"ce37cda6.eebb4","name":"","topic":"","payload":"0","payloadType":"string","repeat":"1","crontab":"","once":false,"x":387.09942626953125,"y":851.54541015625,"wires":[["ec667bf9.daf2f8"]]},{"id":"ec667bf9.daf2f8","type":"Digital Out","z":"ce37cda6.eebb4","name":"","pin":"13","arduino":"","x":578.9545440673828,"y":813.6846361711994,"wires":[]}]

3. Analog In

Screenshot_10_thumb2
This block will read analog value of the ADC pin of the module. Similar to the digital in block you need to trigger the block to read the value. Any input sent to the block will serve as the trigger.
  • Configuration:
    • Pin: pin number of the analog pin to read (Required)
    • Name: Any name desired
  • Input
    • Any input. Used as a trigger
  • Output
    • Value of the pin from 0 to 1024 and the pin number as the topic with prefix A
      • eg: {"payload": 965, "topic":"A0"}
Notes
  • ADC value range 0-1024
[{"id":"b5081d9d.4c3fc","type":"comment","z":"ce37cda6.eebb4","name":"Set MagicWiFiShield ID","info":"","x":622.9601898193359,"y":756.4090270996094,"wires":[]},{"id":"7de26fe6.97ca1","type":"inject","z":"ce37cda6.eebb4","name":"","topic":"","payload":"1","payloadType":"none","repeat":"1","crontab":"","once":false,"x":436.09942626953125,"y":797.54541015625,"wires":[["173bd9b1.b34b46"]]},{"id":"173bd9b1.b34b46","type":"Analog In","z":"ce37cda6.eebb4","name":"","pin":"0","arduino":"","x":596.9601898193359,"y":797.0511169433594,"wires":[[]]}]

4. PWM (Analog Write)

Screenshot_11_thumb2
This block outputs PWM signal from the selected pin
  • Configuration:
    • Pin: pin number for the PWM signal (Required)
    • Name: Any name desired
  • Input
    • value from 0 to 100
      • eg: {"payload": 55}
[{"id":"b5081d9d.4c3fc","type":"comment","z":"ce37cda6.eebb4","name":"Set MagicWiFiShield ID","info":"","x":622.9601898193359,"y":756.4090270996094,"wires":[]},{"id":"9870769e.7c4558","type":"inject","z":"ce37cda6.eebb4","name":"","topic":"","payload":"150","payloadType":"string","repeat":"1","crontab":"","once":false,"x":427.09942626953125,"y":800.54541015625,"wires":[["30605786.7b12c8"]]},{"id":"30605786.7b12c8","type":"PWM","z":"ce37cda6.eebb4","name":"","pin":"13","arduino":"","x":602.9601898193359,"y":801.4942932128906,"wires":[]}]

5. Servo


Screenshot_14_thumb2

This block can be used to control a servo motor with the MagicWiFi module.
  • Configuration:
    • Pin: pin number to which servo motor is attached (Required)
    • Name: Any name desired
  • Input
    • value from 0 to 180 translating from 0 degrees to 180 degrees for servo motor shaft rotation.
      • eg: {"payload" : 120}
[{"id":"b5081d9d.4c3fc","type":"comment","z":"ce37cda6.eebb4","name":"Set MagicWiFiShield ID","info":"","x":622.9601898193359,"y":756.4090270996094,"wires":[]},{"id":"5ba60a66.066754","type":"inject","z":"ce37cda6.eebb4","name":"","topic":"","payload":"0","payloadType":"string","repeat":"1","crontab":"","once":false,"x":400.09942626953125,"y":759.54541015625,"wires":[["a57faf7b.d036f"]]},{"id":"273e4568.eb5b4a","type":"inject","z":"ce37cda6.eebb4","name":"","topic":"","payload":"90","payloadType":"string","repeat":"1","crontab":"","once":false,"x":400.09942626953125,"y":839.54541015625,"wires":[["a57faf7b.d036f"]]},{"id":"a57faf7b.d036f","type":"SERVO","z":"ce37cda6.eebb4","name":"","pin":"12","arduino":"","x":593.9545440673828,"y":808.8692980364337,"wires":[]}]

6. Serial In

Screenshot_15_thumb2

The Serial In block will output anything written to the RX1 of the Arduino Mega module at 115200 baud. You do not need to trigger the module as the data will be delivered in real time.
  • Configuration:
    • Name: Any name desired
  • Output
    • data read from the serial RX0 pin of the MagicWiFi module and the topic as 0x63 to indicate a serial read
      • eg: {"payload": "Your Serial Data Buffer","topic": 0x63}
[{"id":"b5081d9d.4c3fc","type":"comment","z":"ce37cda6.eebb4","name":"Set MagicWiFiShield ID","info":"","x":622.9601898193359,"y":756.4090270996094,"wires":[]},{"id":"902df20b.29dd5","type":"debug","z":"ce37cda6.eebb4","name":"","active":true,"console":"false","complete":"false","x":768.0994262695312,"y":806.54541015625,"wires":[]},{"id":"6f554e89.762f2","type":"Serial In","z":"ce37cda6.eebb4","arduino":"","x":539.9545440673828,"y":806.3096008300781,"wires":[["902df20b.29dd5"]]}]

7. Serial Out



Screenshot_16_thumb2


The serial out block will write anything you send to the TX1 of the Arduino Mega at 115200 baud.
  • Configuration:
    • Name: Any name desired
  • Input
    • data to be written to the serial pin
      • eg:
        • To write a string ==> {"payload": "Your Serial Data to be sent"}
        • To write a byte buffer ==> {"payload": buffername}
[{"id":"b5081d9d.4c3fc","type":"comment","z":"ce37cda6.eebb4","name":"Set MagicWiFiShield ID","info":"","x":622.9601898193359,"y":756.4090270996094,"wires":[]},{"id":"c471d62.9aab828","type":"inject","z":"ce37cda6.eebb4","name":"","topic":"","payload":"Hello","payloadType":"string","repeat":"","crontab":"","once":false,"x":393.09942626953125,"y":798.54541015625,"wires":[["41b1f794.58bef8"]]},{"id":"41b1f794.58bef8","type":"Serial Out","z":"ce37cda6.eebb4","x":586.9545135498047,"y":800.1249694824219,"wires":[]}]