Problem with reconfiguring pins to my own Arduino Uno

Hi,

I've been working on making a prototype Refreshable Braille Display for a national science competition in my country and came across this open source code:

#define BrailleCell_1_1_Expander 0x20
#define BrailleCell_1_1_PORT 0x12
#define BrailleCell_1_1_PIN 0b00000001
#define BrailleCell_1_2_Expander 0x20
#define BrailleCell_1_2_PORT 0x12
#define BrailleCell_1_2_PIN 0b00000010
#define BrailleCell_1_3_Expander 0x20
#define BrailleCell_1_3_PORT 0x12
#define BrailleCell_1_3_PIN 0b00000100
#define BrailleCell_1_4_Expander 0x20
#define BrailleCell_1_4_PORT 0x12
#define BrailleCell_1_4_PIN 0b00000001
#define BrailleCell_1_5_Expander 0x20
#define BrailleCell_1_5_PORT 0x12
#define BrailleCell_1_5_PIN 0b00001000
#define BrailleCell_1_6_Expander 0x20
#define BrailleCell_1_6_PORT 0x12
#define BrailleCell_1_6_PIN 0b01000000

Basically, every individual braille pin must be actuated on its own. But im interested in the long number, specifically the '0b00000001' and so forth. I'm fairly inexperienced but have tried researching what it means but all Ihave gotten is that it is hexadecimal. Does it point to a certain pin on an Arduino? Or is it for something else.

For reference

I want to change these so that digital pins 2 through 7 are being controlled.

I'd appreciate any advice on this as I am really struggling to wrap my head around this.

Justin

I'm fairly inexperienced but have tried researching what it means but all Ihave gotten is that it is hexadecimal.

No, it is binary (the 0b prefix is for binary number, for hexadecimal numbers it's 0x).

I want to change these so that digital pins 2 through 7 are being controlled.

Post complete code, maybe we can help then. What you posted is only a definition section, it doesn't contain any actual code.

0b00000001

The 0b in front means that that is binary notation.

#define BrailleCell_1_1_Expander 0x20
#define BrailleCell_1_1_PORT 0x12
#define BrailleCell_1_1_PIN 0b00000001

That seems to be assigning BrailleCell_1_1_PIN to pin 1 (0b00000001) of port 012 of some device at address 0x20 (0x20 is hexadecimal notation).

If you want to assign to Uno pins you could use: (based on my best guess at what you want to do)

const byte BrailleCell_1_1_PIN = 2;
const byte BrailleCell_1_2_PIN = 3;
// and so on

I prefer using an assignment to a constant more than using #define as the data type is specified.

Yes, exactly I'd like to assign them to an Uno Pin.

void SetBrailleDot(uint8_t cell, uint8_t state)
{
  switch(cell)
  {
    case 1:   // Braille Cell 1        
      for(uint8_t dot = 1; dot<7; dot++)
      {
        if(state & (1<<(dot-1)))
        {
          switch(dot)
          {
            case 1:
              setBrailleDotState(BrailleCell_1_1_Expander, BrailleCell_1_1_PORT, (byte)(BrailleCell_1_1_PIN));
              break;
            case 2:
              setBrailleDotState(BrailleCell_1_2_Expander, BrailleCell_1_2_PORT, (byte)(BrailleCell_1_2_PIN));
              break;
            case 3:
              setBrailleDotState(BrailleCell_1_3_Expander, BrailleCell_1_3_PORT, (byte)(BrailleCell_1_3_PIN));
              break;
            case 4:
              setBrailleDotState(BrailleCell_1_4_Expander, BrailleCell_1_4_PORT, (byte)(BrailleCell_1_4_PIN));
              break;
            case 5:
              setBrailleDotState(BrailleCell_1_5_Expander, BrailleCell_1_5_PORT, (byte)(BrailleCell_1_5_PIN));
              break;
            case 6:
              setBrailleDotState(BrailleCell_1_6_Expander, BrailleCell_1_6_PORT, (byte)(BrailleCell_1_6_PIN));
              break;
          }
        }        
      }
      break;
  }
}

That's where the definitions are used (the code is going through all the pins, telling them if they are raised or lowered).

I don't know if this helps, but the motors' control wires are attached to a breadboard (from ports 2-7) and are connected back to the ground pin.
(see motor.jpg)

This code already works with a lot of Accessibility software (like Apple VoiceOver and Microsoft Narrator). although I don't know if changing the code in the way you suggested would affect the compatibility because the protocol never really references this code directly.

#ifndef BrailleProtocol_h
#define BrailleProtocol_h

#include "BrailleText.h"
#include "SerialCommunication.h"


void parseCommand()
{
  ClearBrailleTextBuffer();
  TextPosition = 0;

  for(uint16_t i = 0; i < StringBufferSize; i++)
  {
    brailleText[i] = inputString[i];
  }
  switch(mode)
  {
    case 0:
      PrepareBrailleTextFromBuffer();
      requireDisplayUpdate = 1;
      break;
    case 1:
      PrepareBrailleTextFromBuffer();
      requireDisplayUpdate = 1;
      break;
  }
  
}



#endif

Sorry if this is hard to understand because I know I'm talking about one specific topic but I appreciate everybody's help here.

Where can I find that library. I have not been successful with a Google search.

What are you trying to do? You may have to modify that library to work with your Uno, I don't know.

Post complete code! And post links to the libraries used!

https://github.com/ChrisUlbi/BrailleDisplay/tree/master/Software/Firmware/Braille_Firmware

The files that I'm looking at in particular are BrailleCell.h, BrailleProtocol.h and PortExpander.h

BrailleCell.h:

#ifndef BrailleCell_h
#define BrailleCell_h

#include "Settings.h"

#define Transistor5V_Pin 21
#define TransistorGND_Pin 20

#define BrailleTime 50

void setBrailleDotState(byte address, byte port, byte pin);
void clearAllBrailleCells();

//Cell 1

#define BrailleCell_1_1_Expander 0x20
#define BrailleCell_1_1_PORT 0x12
#define BrailleCell_1_1_PIN 0b00000001
#define BrailleCell_1_2_Expander 0x20
#define BrailleCell_1_2_PORT 0x12
#define BrailleCell_1_2_PIN 0b00000010
#define BrailleCell_1_3_Expander 0x20
#define BrailleCell_1_3_PORT 0x12
#define BrailleCell_1_3_PIN 0b00000100
#define BrailleCell_1_4_Expander 0x20
#define BrailleCell_1_4_PORT 0x12
#define BrailleCell_1_4_PIN 0b00000001
#define BrailleCell_1_5_Expander 0x20
#define BrailleCell_1_5_PORT 0x12
#define BrailleCell_1_5_PIN 0b00001000
#define BrailleCell_1_6_Expander 0x20
#define BrailleCell_1_6_PORT 0x12
#define BrailleCell_1_6_PIN 0b01000000

void SetupBraille()
{
  pinMode(Transistor5V_Pin, OUTPUT);
  pinMode(TransistorGND_Pin, OUTPUT);
  digitalWrite(Transistor5V_Pin, LOW);
  digitalWrite(TransistorGND_Pin, LOW);
  //clearAllBrailleCells();
}
 
/*void SetBraille(String stringToDisplay)
{
  for(uint8_t i = 0; (stringToDisplay[i] != "") && (stringToDisplay[i] != "\n") && (i < NumberOfBrailleCells-1); i++)
  {
    stringToDisplay.toUpperCase();
    switch(stringToDisplay[i])
    {
      case 'A':
      case '1':
        SetBrailleDot(i,Braille_A_1);
        break;
      case 'B':
      case '2':
        SetBrailleDot(i,Braille_B_2);
        break;
      case 'C':
      case '3':
        SetBrailleDot(i,Braille_C_3);
        break;
      case 'D': 
      case '4':
        SetBrailleDot(i,Braille_D_4);
        break;
      case 'E':
      case '5':
        SetBrailleDot(i,Braille_E_5);
        break;
      case 'F':
      case '6':
        SetBrailleDot(i,Braille_F_6);
        break;
      case 'G':
      case '7':
        SetBrailleDot(i,Braille_G_7);
        break;
      case 'H':
      case '8':
        SetBrailleDot(i,Braille_H_8);
        break;
      case 'I':
      case '9':
        SetBrailleDot(i,Braille_I_9);
        break;
      case 'J':
      case '0':
        SetBrailleDot(i,Braille_J_0);
        break;  
      case 'K':
        SetBrailleDot(i,Braille_K);
        break;
      case 'L':
        SetBrailleDot(i,Braille_L);
        break;
      case 'M':
        SetBrailleDot(i,Braille_M);
        break;
      case 'N':
        SetBrailleDot(i,Braille_N);
        break;
      case 'O':
        SetBrailleDot(i,Braille_O);
        break;
      case 'P':
        SetBrailleDot(i,Braille_P);
        break;
      case 'Q':
        SetBrailleDot(i,Braille_Q);
        break;
      case 'R':
        SetBrailleDot(i,Braille_R);
        break;
      case 'S':
        SetBrailleDot(i,Braille_S);
        break;
      case 'T':
        SetBrailleDot(i,Braille_T);
        break;
      case 'U':
        SetBrailleDot(i,Braille_U);
        break;
      case 'V':
        SetBrailleDot(i,Braille_V);
        break;
      case 'W':
        SetBrailleDot(i,Braille_W);
        break;
      case 'X':
        SetBrailleDot(i,Braille_X);
        break;
      case 'Y':
        SetBrailleDot(i,Braille_Y);
        break;
      case 'Z':
        SetBrailleDot(i,Braille_Z);
        break;
    }
  }
}*/


void SetBrailleDot(uint8_t cell, uint8_t state)
{
  switch(cell)
  {
    case 1:   // Braille Cell 1        
      for(uint8_t dot = 1; dot<7; dot++)
      {
        if(state & (1<<(dot-1)))
        {
          switch(dot)
          {
            case 1:
              setBrailleDotState(BrailleCell_1_1_Expander, BrailleCell_1_1_PORT, (byte)(BrailleCell_1_1_PIN));
              break;
            case 2:
              setBrailleDotState(BrailleCell_1_2_Expander, BrailleCell_1_2_PORT, (byte)(BrailleCell_1_2_PIN));
              break;
            case 3:
              setBrailleDotState(BrailleCell_1_3_Expander, BrailleCell_1_3_PORT, (byte)(BrailleCell_1_3_PIN));
              break;
            case 4:
              setBrailleDotState(BrailleCell_1_4_Expander, BrailleCell_1_4_PORT, (byte)(BrailleCell_1_4_PIN));
              break;
            case 5:
              setBrailleDotState(BrailleCell_1_5_Expander, BrailleCell_1_5_PORT, (byte)(BrailleCell_1_5_PIN));
              break;
            case 6:
              setBrailleDotState(BrailleCell_1_6_Expander, BrailleCell_1_6_PORT, (byte)(BrailleCell_1_6_PIN));
              break;
          }
        }        
      }
      break;
  }
}

void ClearBrailleDotState(byte address, byte port, byte pin)
{
  digitalWrite(Transistor5V_Pin, LOW);
  digitalWrite(TransistorGND_Pin, HIGH);
  
  Wire.beginTransmission((byte)address);
  Wire.write((byte)port); // address port
  Wire.write((byte)pin);  // value to send
  Wire.endTransmission();
  
  delay(BrailleTime);

  digitalWrite(TransistorGND_Pin, LOW);
  digitalWrite(Transistor5V_Pin, LOW);  
  
  Wire.beginTransmission((byte)address);
  Wire.write((byte)port); // address port
  Wire.write((byte)0x00);  // value to send
  Wire.endTransmission();
}

void setBrailleDotState(byte address, byte port, byte pin)
{
  digitalWrite(Transistor5V_Pin, LOW);  
  digitalWrite(TransistorGND_Pin, LOW);
  
  Wire.beginTransmission((byte)address);
  Wire.write((byte)port); // address port
  Wire.write((byte)(~pin));  // value to send
  Wire.endTransmission();


  
  digitalWrite(TransistorGND_Pin, LOW);
  digitalWrite(Transistor5V_Pin, HIGH);
  
  delay(BrailleTime);
  
  digitalWrite(TransistorGND_Pin, LOW);
  digitalWrite(Transistor5V_Pin, LOW);
  
  Wire.beginTransmission((byte)address);
  Wire.write((byte)port); // address port
  Wire.write((byte)0x00);  // value to send
  Wire.endTransmission();
  
 
}

void clearAllBrailleCells()
{
  for(uint8_t cell = 1; cell < NumberOfBrailleCells; cell++)
  {
    switch(cell)
    {
      case 1:   // Braille Cell 1        
        for(uint8_t dot = 1; dot<7; dot++)
        {
            switch(dot)
            {
              case 1:
                ClearBrailleDotState(BrailleCell_1_1_Expander, BrailleCell_1_1_PORT, (byte)(BrailleCell_1_1_PIN));
                break;
              case 2:
                ClearBrailleDotState(BrailleCell_1_2_Expander, BrailleCell_1_2_PORT, (byte)(BrailleCell_1_2_PIN));
                break;
              case 3:
                ClearBrailleDotState(BrailleCell_1_3_Expander, BrailleCell_1_3_PORT, (byte)(BrailleCell_1_3_PIN));
                break;
              case 4:
                ClearBrailleDotState(BrailleCell_1_4_Expander, BrailleCell_1_4_PORT, (byte)(BrailleCell_1_4_PIN));
                break;
              case 5:
                ClearBrailleDotState(BrailleCell_1_5_Expander, BrailleCell_1_5_PORT, (byte)(BrailleCell_1_5_PIN));
                break;
              case 6:
                ClearBrailleDotState(BrailleCell_1_6_Expander, BrailleCell_1_6_PORT, (byte)(BrailleCell_1_6_PIN));
                break;
            }     
        }
        break;
    }
  }  
}

#endif

BrailleProtocol.h:

#ifndef BrailleProtocol_h
#define BrailleProtocol_h

#include "BrailleText.h"
#include "SerialCommunication.h"


void parseCommand()
{
  ClearBrailleTextBuffer();
  TextPosition = 0;

  for(uint16_t i = 0; i < StringBufferSize; i++)
  {
    brailleText[i] = inputString[i];
  }
  switch(mode)
  {
    case 0:
      PrepareBrailleTextFromBuffer();
      requireDisplayUpdate = 1;
      break;
    case 1:
      PrepareBrailleTextFromBuffer();
      requireDisplayUpdate = 1;
      break;
  }
  
}



#endif

I understand that I'm being a bit confusing so I'll try be a bit more clearer.

Basically, I' not sure if you're familiar with a braille display, but in order for it to work with certain software it must have a protocol so that the software can easily send the braille text to the Arduino/other devices. If i changed the whole 'BrailleCell_Expander/port/pin' to just:

#define BrailleCellPin1 2
         #define BrailleCellPin2 3

should it still work with my Uno?

The individual motors (which each push up or down a braille pin) correspond to one input pin each on the Uno (the pins 2 - 7). Depending on what word is being highlighted by the mouse into the Uno on the Computer/User device, the pins will raise or lower according to the letters in the word. From what I can gather here, these definitions are for a different type of Arduino that deals with pins differently?

That library was written with a certain circuit configuration in mind. I see an I2C port expander, keyboard and RTC plus others. It is unrealistic, I think, to expect to easily modify that code to work with a bare Uno unless you know much more about Arduino programming.

I ask again, what are you trying to do?

I'm trying to use the Arduino to handle the braille text from the computer and send it through to the motors, telling them to either activate or stay deactivated.

A braille display takes the text from a computer screen and outputs it into physical braille that can be read. Software on the computer separate to this handles the screen scanning and translation and outputs that to the connected braille display. The braille display then figures out what to do with the string it has been sent and breaks it up, letter by letter, Activating the appropriate pins.

For this software to do this, it must understand where to send the information using the protocol (BrailleProtocol.h)

I understand that there are other features programmed into it but I could remove those files, and in the final .ino file. But, you say that it may not be that simple to do just that and that I perhaps may have to scrap this altogether.

What I want to do with the code is change it so that it actually activates my pins, not these pins that probably aren't even on my board.

Sorry, I've probably added a few more problems into the mix here but basically:

  1. Could I change BrailleCell.h so that the software activates my chossen pins?
  2. Use my Uno to act as a 'middleman' so to speak so that i can get my motors to activate?