Interface and Application Programming

Interface and Application Programming

This weeks assignment was about designing and building a wired &/or wireless network connecting at least two processors. I decided to do something, that would be useful for my future project - an wireless connection between my smart planter and my computer, where I will develop an application that will show, when the water tank is empty and when it is full.

A quick intro: for that assignment I used my final presentation board. As I already explained in Output & Input assignment, this board will control all the Output devices(water pump, LED strip, WS2812) depending on input sensors(water level, humidity & light). Here is the schematic and board:

Bluetooth Module

I used an HC05 bluetooth module (Datasheet ). The module uses a serial connection over the RX and TX pin and my final board processor ATmega328 has such a pins, there should be no problem. Here is an instruction, how to set and connect the bluetooth module:

  • Connect EN pin to 5V (high level) and GND to ground
  • Hold RESET button while powering on
  • Use Arduino serial monitor to write AT commands to bluetooth module and configure name, password and etc(All the commands can be found in datasheet above)
  • Repower without EN pin and without holding RESET button and connect to bluetooth device normally

After that I could find bluetooth on my laptop and connect it:

After that I programmed my board using serial communication:

So now, if I will open serial Monitor for a device - Bluetooth, I will see what bluetooth module receives :

Serial communication

I also did serial communication between two boards(using wires). For that it has to be a common ground between the two boards(that means that ground of boards are connected) or else it will not function properly. Also, note that TX goes to RX and RX goes to TX. Here is the sample code for sender board and receiver one:

Application Programming

I did set up a processing app to work with the bluetooth module on my PCB. The app simply connects to the bluetooth module and receives the information (0 when water tank is empty and 1 when it is full).

Here is the code:

            import processing.serial.*;

            boolean toggle = true;
            PImage LEDonImage;
            PImage LEDoffImage;
            Serial myPort;
            int portNumber;

            void setup() {
            size(500, 500);

            LEDonImage = loadImage("LEDonImage.png");
            LEDonImage.resize(500, 500);
            LEDoffImage = loadImage("LEDoffImage.png");
            LEDoffImage.resize(500, 500);

            image(LEDoffImage, 0, 0);

            for (int count = 0; count < Serial.list().length; count++){
            if (Serial.list()[count].length() > 20){
            if (Serial.list()[count].substring(0,21).equals("/dev/cu.LANABT-SPPDev")){
            portNumber = count;
            }
            }
            }

            println(Serial.list());
            println(portNumber);

            String portName = Serial.list()[portNumber];
            myPort = new Serial(this, portName, 9600);

            //myPort.write("0");
            //mainLoop();
            }

            char water = 0;
            char last = 1;


            void serialEvent(Serial myPort) {
            water = myPort.readChar();
            if(water == 0){
            image(LEDonImage, 0, 0);
            //println("water on");
            }
            else{
            image(LEDoffImage, 0, 0);
            //println("water off");
            }
            println(water);
            }



            void draw() {
            if(water == '0'){
            image(LEDonImage, 0, 0);
            //println("water on");
            }
            else{
            image(LEDoffImage, 0, 0);
            //println("water off");
            }
            }
            

So, that how it looks:

And live demo:

Files


Board Shematic

Board

Arduino code

Processing application