Hacking Ardublock
Adding an extension to Ardublock
Extended From: How to hack ardublock
Handling the dependencies
- Fork and clone Arduino form github
- Import openblocks and Ardublock into eclipse
- Import arduino-builder,arduino-dore and processing from Arduino project into eclipse
- Modify the buildpath of Ardublock and add the above 3 projects as dependency. Add openblocks and an dependency as well.
- Modify pom.xml in Ardublock,delete openblocks and Arduino dependency entries(They became obsolete over time and was no longer maintained)
- Continue to delete the install-arduino-pde execution entry in pom.xml
You should now see no compiling errors within the projects. You may have a few warnings about the java compiler version. Just change the compilation configs to make eclipse happy.
**If you are using other IDEs like IntelliJ, please use your own judgement to appropriately adapt the steps.
Adding an LED module
You can use the Ardublock article to do the same, here are some basic ideas:
- Add one BlockGenus with your own parameters
- Register the BlockGenus into one BlockDrawer so that you’ll see the newly added module in the GUI, inside the designated drawer menu.
- If you need new image, tag or other custom resources to go with the new module, you need to add them to the resources folder, with i18n entries. Modify the
ardublock<_{country_code}>.properties
i18n file to achieve that. - Modify block-mapping.properties and point the module to use the corresponding
Translator
Java class. You need to extend theTranslator
class if you want to dive in deeper.
Export and install
- Right click Ardublock and Openblocks projects and export a jar package
- You need to check the
export with all resources
checkbox to include the image and configuration files. - Put your jar into the Arduino tools folder. Be careful with the folder names as one of them is said to be case sensitive. See the official tutorial for sure.
Test
- Open the Arduino installation folder
- Run Arduino-debug and you can see the logs in the console window.
- Click on
Tools
->Ardublock
- Drag your new module and test the functions.
Adding an I2C module
You need to know how to add your custom header file and c++ file
If you want to use I2C modules like an I2C mounted 1602 LCD, you need to add the I2C c++ libraries for easier coding. The original Ardublock can only generate a single ino file. Here is how:
- First you create your new module, of course. See steps above. Let’s call the new module I2C.
- Modify the
Translator
base class and add acustomHeaderFileSet
private member, maybe next to its ownheaderFileSet
member. - Add a
addCustomHeaderFile
API for clients and derived classes to manipulate thecustomHeaderFileSet
- Modify your I2C module and call your API to add the custom header and/or c++ file.
- Import your header files and cpp file to eclipse. You should keep them well in your classpath.
- Next you need to use file manipulation to read from your jar file, and write the file stream into the Aruino temp project location. You don’t want to write to the destination, since they would clobber the source file to import.
- Find the Aruino
Editor
instance along theContext
instance and open your temp header and/or c++ file. - Set the editor to the ino file, or else your translated text will be writing to the last file you opened by default.
Conclusion
You can easily add new module for simple input and output.
You have to drill down to the Translator
core for advanced code generation, but it is not a very difficult task because the source code is quite well orgnized. Thumbs up to the Arublock team.