WEEK 14

For this week I decided to program my application with MIT App Inventor for my final project. cause my final project is a score board and I must program an application to control it.

INTERFACE AND APPLICATION PROGRAMMING

Group assignment :

*Document your work on the group work page and reflect on your individual page what you learned.

To see our group assignment click here

Individual assignments :

Learning outcomes

Implement a Graphical User Interface (GUI) using programming and explore protocols to communicate with an MCU board.

Workflow

Materials

I am using an Arduino board to program an ATmega328P chip, which I then incorporate into my own custom board. This custom board is designed to control an LED panel. Specifically, I have created a board that utilizes the programmed ATmega328P chip, which I initially program using an Arduino Uno development board.

I also used bluetooth module

The module I used is P10 Green LED to display number.

Programming

Information

Note that the P10 module use SPI protocol to communicate with the MCU.

below I provide how P10 module and bluetooth module are connected to the MCU.

MCU pins P10 pins Bluetooth pins
9 OE -
6 A -
7 B -
13 CLK -
8 SCLK -
11 R_DATA -
Tx - Rx
Rx - Tx
Gnd Gnd Gnd
5V - Vcc

I used Arduino IDE and below is the source code

#include <SPI.h>
#include <DMD.h>
#include <TimerOne.h>
#include "Font_6x14.h"

//Fire up the DMD library as dmd
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1


// les variables pour la programmation de l'afficheur
char compteruniTgauchescore = '0';
char compteruniTgaucheremplacement = '0';
char compteruniTdroitescore = '0';
char compteruniTdroiteremplacement = '0';
char compterdizaiNdroitescore = '0';
char compterdizaiNdroitesremplacement = '0';
char compterdizaiNgauchescore = '0';
char compterdizaiNgaucheremplacement = '0';

char nombreGauche1[2] = { '0', '0' }; // Nombre gauche pour l'affichacge du score
char nombreDroite1[2] = { '0', '0' };

char nombreGauche0[2] = { '0', '0' }; // Nombre gauche pour l'affichage du remplacement
char nombreDroite0[2] = { '0', '0' };

char bluetooth_message = 0 ;


DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

void ScanDMD() {
  dmd.scanDisplayBySPI();
}

void setup(void) {
  Serial.begin(9600);
  for (int x = 0; x < 6; x++)
    pinMode(x, INPUT_PULLUP);
  Timer1.initialize(200);
  Timer1.attachInterrupt(ScanDMD);
  dmd.clearScreen(true);
  Serial.begin(9600);
  delay(2000); //waiting time to start 
}

// function to increment right digit of left number
char compter_uniT_gauche(char ___message) {
  if(Serial.available())
  {
    if (___message =='L')
    {
      compteruniTgauchescore++;
    }
    if (compteruniTgauchescore > '9')
    compteruniTgauchescore = '0';
    return compteruniTgauchescore;
  }
}

// function to increment right digit of right number
char compter_uniT_droite(char __message) {
  if(Serial.available())
  {
    if (__message=='R' )
    {
      compteruniTdroitescore++;
    }
    if (compteruniTdroitescore > '9')
      compteruniTdroitescore = '0';
  return compteruniTdroitescore;
  }
}

// function to increment left digit of left number
char compter_dizaiN_gauche(char message,) {
  if(Serial.available())
  {
    if (message=='G')
    {
      compterdizaiNgauchescore++;
    }
    if (compterdizaiNgauchescore > '9')
      compterdizaiNgauchescore = '0';
    return compterdizaiNgauchescore;
  }
}

// function to increment left digit of right number
char compter_dizaiN_droite(char _message) {
  if(Serial.available())
  {
    if (_message=='D')
    {
      compterdizaiNdroitescore++;
    }
    if (compterdizaiNdroitescore > '9')
      compterdizaiNdroitescore = '0';
    return compterdizaiNdroitescore;
  }
}

// display numbers
void afficher_score() {
  dmd.clearScreen(true);
  dmd.selectFont(Font_6x14);
  dmd.drawString(0, 0, nombreGauche1, 2, GRAPHICS_NORMAL);
  for (int x = 14; x < 21; x++) {
    for (int y = 6; y <9 ; y++)
      dmd.writePixel(x, y, GRAPHICS_NORMAL, 1);
  }
  dmd.drawString(19, 0, nombreDroite1, 2, GRAPHICS_NORMAL);
}

void loop() {
  if(!Serial.available())
    Serial.flush();
  bluetooth_message = Serial.read();
  if (Serial.available()) 
  {
    afficher_score();
    if((bluetooth_message=='G') || (bluetooth_message=='L'))
    {
      nombreGauche1[0] = compter_dizaiN_gauche(bluetooth_message);
      nombreGauche1[1] = compter_uniT_gauche(bluetooth_message);
      dmd.writePixel(6, 0, GRAPHICS_NORMAL, 1);
      dmd.writePixel(7, 0, GRAPHICS_NORMAL, 1);
      //dmd.drawString(1, 0, nombreGauche1, 2, GRAPHICS_NORMAL);
    }
    if((bluetooth_message== 'D') || (bluetooth_message == 'R'))
    {
      nombreDroite1[0] = compter_dizaiN_droite(bluetooth_message);
      nombreDroite1[1] = compter_uniT_droite(bluetooth_message);
      dmd.writePixel(24, 0, GRAPHICS_NORMAL, 1);
      dmd.writePixel(25, 0, GRAPHICS_NORMAL, 1);
      //dmd.drawString(19, 0, nombreDroite1, 2, GRAPHICS_NORMAL);
    }
  }
}

This code comes from a most complete code for my final project that is

Explain GUI

We use App Inventor to make our GUI.

App Inventor is a cloud-based tool, which means you can create apps for phones or tablets right in your web browser. This website offers all the support you’ll need to build apps:

Use this link to start you session and create apps.

We design our app with two screens.

Firstly we have screen 1 which is the homepage and its code is show below.

App Inventor allow us to create app by designing UI in one hand and in the other hand make code that’s going animate our UI.

This is homepage interface show below with it source code.

source code

The programming code is based on blocks, where each block is linked to objects in the user interface enable the creation of events. Some of these blocks have special roles.

Other blocks are dedicated to programming logic and establish the code’s structure. These include condition blocks, math blocks, logic blocks, and more.

All these tools make programming easy to do.

I show below the App interface

And this is the source code

Bluetooth communication between app and the display based on hc-05

Why Bluetooth communication

Bluetooth communication is a wireless technology that allows devices to exchange data over short distances. Here’s a brief explanation of how Bluetooth communication works:

Pairing: Before two Bluetooth devices can communicate, they need to go through a pairing process. During pairing, the devices establish a secure connection and exchange encryption keys to ensure data privacy.

Bluetooth Profiles: Bluetooth devices support various profiles, which define specific functionalities and protocols for different types of communication. Examples include the Hands-Free Profile (HFP) for phone calls and the Advanced Audio Distribution Profile (A2DP) for streaming audio.

Master-Slave Relationship: In a Bluetooth connection, one device acts as the master, and the other device(s) act as slaves. The master device initiates the connection and controls the communication.

Frequency Hopping: Bluetooth communication operates in the 2.4 GHz ISM (Industrial, Scientific, and Medical) band. To avoid interference from other devices operating in the same frequency range, Bluetooth uses a technique called frequency hopping. It rapidly switches between multiple frequency channels within the band.

Data Transmission: Bluetooth uses a technique called Gaussian Frequency Shift Keying (GFSK) to modulate and transmit data. It divides the data into packets and transmits them in short bursts over the chosen frequency channels.

Connection Management: Once devices are paired, they can maintain a connection for data transfer. They can establish and release connections as needed, allowing for efficient power management.

Profiles and Services: Bluetooth devices provide specific services and features based on supported profiles. For example, a Bluetooth headset supports audio streaming, call control, and microphone functionality through the Hands-Free Profile.

Overall, Bluetooth communication enables wireless data transfer between devices by establishing secure connections, utilizing specific profiles, and managing data transmission over frequency channels. (this information is provided by chat gpt)

So I chose bluetooth communication because it’s simple to establish the communication.

Hence, my app via bluetooth connect itself with the display and when the communication is established the app show new interface that display scoring. for video viewing concerns please download the video