Announcement

Collapse
No announcement yet.

Protocol I2C between Arduino Micro and 4duino 2.4" using SDA and SCL. How to start?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Protocol I2C between Arduino Micro and 4duino 2.4" using SDA and SCL. How to start?

    Hello everybody.
    I am new to the forum.
    I need to send data from an arduino Micro to the 4Duino 2.4", via an RJ12 cable, using the protocol I2C, and so using the bus SDA and SCL.
    Where can I find similar topic or tutorial that could help me starting?

    I will use the Arduino IDE for the purpose, and I will need to program the Arduino as master and 4Duino as slave, so that the 4Duino will be used (initially) only as screen (further development implemented in future).

    Any good link is really appreciated, because at the moment I am not finding anything useful.
    thank you very much

  • #2
    Hello,

    Welcome to the forum,

    The 4Duino is an Arduino processor (Leonardo 32u4) which then talks to the 4D graphics processor so the communication between the 4Duino and the Arduino Micro is an Arduino to Arduino setup.

    I found this article about the subject which may help.

    http://www.instructables.com/id/I2C-between-Arduinos/

    I hope this helps

    Best regards

    Paul

    Comment


    • #3
      Thank you very much for replying and for the link.
      Hope it will help

      Comment


      • #4
        Hi Paulelio

        I tried to upload the code found at the link.
        I wired the 2 boards as shown in the pictures.
        I checked the schematic for both boards and it replicates the pictures.

        on 4duino a LED is in D13 which means it is pin 13, I believe.

        the code doesn't work apparently. the LED doesn't blink. the arduino (ArduPLC Micro) is powered via the usb port.
        The 4duino is powered via the RJ12 cable connected to the ArduPLC Micro which takes 5Vdc from the PIN2 of the RJ12 cable to the pin Vin, and the GND (PIN3) to GND on the 4duino.
        SDA and SCL are connected accordingly.

        any possible mistake? I didn't change the code found at the link because it seemed possible to make it work. I have doubts about the pin assigned to the built in LED though.

        any link that explain how to print on screen the values, instead of blinking a led?

        thank you very much
        Attached Files

        Comment


        • #5
          Hi,

          I have tried the same setup and code and you are correct, it doesn't seem to work. I added a serial print to the code and it does appear to work fine apart from the code in the loop which flashes the LED. Could you try uploading this code to the 4Duino and with the 4Duino connected to your PC open the Serial Monitor at 115200 baud.

          #include <Wire.h>
          int LED = 13;
          int x = 0;
          void setup() {
          // Define the LED pin as Output
          Serial.begin(115200);
          pinMode (LED, OUTPUT);

          // Start the I2C Bus as Slave on address 9
          Wire.begin(9);
          // Attach a function to trigger when something is received.
          Wire.onReceive(receiveEvent);
          }
          void receiveEvent(int bytes) {
          x = Wire.read(); // read one character from the I2C
          Serial.println(x);
          digitalWrite(LED, HIGH);
          delay(200);
          digitalWrite(LED, LOW);
          delay(200);
          }
          void loop() {
          //If value received is 0 blink LED for 200 ms
          if (x == '0') {
          digitalWrite(LED, HIGH);
          delay(200);
          digitalWrite(LED, LOW);
          delay(200);
          }
          //If value received is 3 blink LED for 400 ms
          if (x == '3') {
          digitalWrite(LED, HIGH);
          delay(400);
          digitalWrite(LED, LOW);
          delay(400);
          }
          }

          I hope this helps

          Best regards

          Paul

          Comment


          • #6
            Hi Pauleilio

            Yes, this works fine, with the serial monitor
            thank you very much.

            Any tutorial about how to print the values on the 4Duino LCD?

            I am following the 4Duino datasheet
            https://www.4dsystems.com.au/product...heet_R_1_5.pdf

            but i feel I need something more on the application point of view

            thank you for the help

            Comment


            • #7
              Hi,

              This code would be a good template on how to print values on the screen.

              Code:
              //
              // NB! This is a file generated from the .4Dino file, changes will be lost
              //     the next time the .4Dino file is built
              //
              #define RESETLINE     30
              
              #define DisplaySerial Serial1
              
              
              // uncomment to log SPE errors messages to Serial (serial monitor)
              #define LOG_MESSAGES
              
              #include "Picaso_Serial_4DLib.h"
              #include "Picaso_Const4D.h"
              
              Picaso_Serial_4DLib Display(&DisplaySerial);
              
              // routine to handle ESP Serial errors
              void mycallback(int ErrCode, unsigned char Errorbyte)
              {
              #ifdef LOG_MESSAGES
                const char *Error4DText[] = {"OK\0", "Timeout\0", "NAK\0", "Length\0", "Invalid\0"} ;
                Serial.print(F("Serial 4D Library reports error ")) ;
                Serial.print(Error4DText[ErrCode]) ;
                if (ErrCode == Err4D_NAK)
                {
                  Serial.print(F(" returned data= ")) ;
                  Serial.println(Errorbyte) ;
                }
                else
                  Serial.println(F("")) ;
                while (1) ; // you can return here, or you can loop
              #else
                // Pin 13 has an LED connected on most Arduino boards. Just give it a name
              #define led 13
                while (1)
                {
                  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
                  delay(200);                // wait for a second
                  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
                  delay(200);                // wait for a second
                }
              #endif
              }
              // end of routine to handle Serial errors
              
              
              void setup()
              {
              // Ucomment to use the Serial link to the PC for debugging
              //  Serial.begin(115200) ;        // serial to USB port
              // Note! The next statement will stop the sketch from running until the serial monitor is started
              //       If it is not present the monitor will be missing the initial writes
              //    while (!Serial) ;             // wait for serial to be established
              
                pinMode(RESETLINE, OUTPUT);       // Picaso reset pin
              digitalWrite(RESETLINE, 1);       // Reset Display, using shield
                delay(100);                       // wait for it to be recognised
              digitalWrite(RESETLINE, 0);       // Release Display Reset, using shield
                delay(3000) ;                     // give display time to startup
              
                // now start display and ESP as Serial lines should have 'stabilised'
                DisplaySerial.begin(200000) ;     // Hardware serial to Display, same as SPE on display is set to
                Display.TimeLimit4D = 5000 ;      // 5 second timeout on all commands
                Display.Callback4D = mycallback ;
              
                Display.gfx_ScreenMode(PORTRAIT) ; // change manually if orientation change
                // put your setup code here, to run once:
              } // end Setup **do not alter, remove or duplicate this line**
              
              void loop()
              {
                // put your main code here, to run repeatedly:
              Display.txt_MoveCursor (1,0);
              Display.println ("Hello World");
              
              Display.println ("This is the second line");
              
              Display.txt_MoveCursor (6,0);
              Display.print ("This is the fourth line");
              }
              You will find a full list of commands in this datasheet.

              https://www.4dsystems.com.au/product...nual_R_2_0.pdf

              I hope this helps

              Best regards

              Paul



              Comment

              Working...
              X