Home>
I want to convert an Arduino NANO program created in Arduino IDE into a Ruby program that writes to GR-CITRUS What you ’ve done so far

We have manufactured wireless robots using ArduinoNANO microcomputers for control, NodeMCU microcomputers for communication, and BLYNK for smartphone applications for operation. The control part was changed to GR-CITRUS of Ruby microcomputer instead of ArduinoNANO.
The ArduinoNANO program and Node-MCU program operate without problems, serial communication is performed between the microcomputers using the RTX pin, and the Node-MCU and the wireless device operate in a WiFi environment.
The purpose is to convert this ArduinoNANO microcomputer to GR-CITRUS and to perform the same operation. The program I created while having little experience in Ruby programming did not work.

~ Key points ~

-ArduinoNANO and Node-MCU send and receive data via serial communication with RTX pin
・ The controller uses the BLYNK app
・ GR-CITRUS and Node-MCU also want to communicate serially with the RTX pin.
・ GR-CITRUS and Node-MCU programs don't work but don't work

Development environment

-ArduinoNANO and Node-MCU programs developed with Arduino IDE
・ Node-MCU can be operated in the WiFi environment using the smartphone application BLYNK
・ The GR-CITRUS program is developed by Rubic
-The robot is moving via a motor driver with four-wheel drive and direction and PWM control.

Error message

I don't know what's wrong because I don't even get an error message.
Writing to GR-CITRUS with Rubic is possible without problems.

Applicable source code
// ArduinoNANO program
// Setting and specifying pins to handle
#define FENA 3
#define FENB 5
#define RENA 9
#define RENB 11
#define FIN1 4
#define FIN2 33
#define FIN3 6
#define FIN4 37
#define RIN1 10
#define RIN2 25
#define RIN3 12
#define RIN4 29
int PWM = 70, Pwm1 = 95, Pwm2 = 105, Pwm3 = 95, Pwm4 = 105;// PWM initial setting
char mode = 1;
int inc, inc1, inc2, inc3, inc4, tt, ttc = 1000;\\ Store data received via serial communication
int m1, m2, m3, m4;
unsigned char sw1 = 0, sw2 = 0;
void setup () {
  Serial.begin (9600);
  // pin setting
  pinMode (FENA, OUTPUT);
  pinMode (FENB, OUTPUT);
  pinMode (RENA, OUTPUT);
  pinMode (RENB, OUTPUT);
  pinMode (FIN1, OUTPUT);
  pinMode (FIN2, OUTPUT);
  pinMode (FIN3, OUTPUT);
  pinMode (FIN4, OUTPUT);
  pinMode (RIN1, OUTPUT);
  pinMode (RIN2, OUTPUT);
  pinMode (RIN3, OUTPUT);
  pinMode (RIN4, OUTPUT);
}
// Set the movement of each motor sent to the motor driver
void Mov (int A, int B, int C, int D) {
  if (A == 0)
  {
  } else if (A == 1) {
    digitalWrite (FIN1, HIGH);
    digitalWrite (FIN2, LOW);
    analogWrite (FENA, Pwm1);
  } else if (A == 2) {
    digitalWrite (FIN1, LOW);
    digitalWrite (FIN2, HIGH);
    analogWrite (FENA, Pwm1);
  }
  if (B == 0)
  {
  } else if (B == 1) {
    digitalWrite (FIN3, HIGH);
    digitalWrite (FIN4, LOW);
    analogWrite (FENB, Pwm2);
  } else if (B == 2) {
    digitalWrite (FIN3, LOW);
    digitalWrite (FIN4, HIGH);
    analogWrite (FENB, Pwm2);
  }
  if (C == 0)
  {
  } else if (C == 1) {
    digitalWrite (RIN1, HIGH);
    digitalWrite (RIN2, LOW);
    analogWrite (RENA, Pwm3);
  } else if (C == 2) {
    digitalWrite (RIN1, LOW);
    digitalWrite (RIN2, HIGH);
    analogWrite (RENA, Pwm3);
  }
  if (D == 0)
  {
  } else if (D == 1) {
    digitalWrite (RIN3, HIGH);
    digitalWrite (RIN4, LOW);
    analogWrite (RENB, Pwm4);
  } else if (D == 2) {
    digitalWrite (RIN3, LOW);
    digitalWrite (RIN4, HIGH);
    analogWrite (RENB, Pwm4);
  }
}
// Serial communication part (storage of errors and received data)
void loop () {
  switch (mode){
    case 1:
      inc = Serial.read ();
      if (inc! = -1)
      {
        inc1 = inc;
        mode = 2;
        tt = 0;
        break;
      }
      break;
    case 2:
      inc = Serial.read ();
      tt ++;
      if (inc! = -1)
      {
        inc2 = inc;
        mode = 3;
        tt = 0;
        break;
      }
      if (tt>ttc)
      {
        mode = 1;
        Serial.print ("NG");
        Serial.print (tt);
        Serial.print ("? 2 \ n");
        tt = 0;
        break;
      }
      break;
    case 3:
      inc = Serial.read ();
      tt ++;
      if (inc! = -1)
      {
        inc3 = inc;
        mode = 4;
        tt = 0;
        break;
      }
      if (tt>ttc)
      {
        mode = 1;
        Serial.print ("NG");
        Serial.print (tt);
        Serial.print ("? 3 \ n");
        tt = 0;
        break;
      }
      break;
    case 4:
      inc = Serial.read ();
      tt ++;
      if (inc! = -1)
      {
        inc4 = inc;
        mode = 5;
        tt = 0;
        break;
      }
      if (tt>ttc)
      {
        mode = 1;
        Serial.print ("NG");
        Serial.print (tt);
        Serial.print ("? 4 \ n");
        tt = 0;
        break;
      }
      break;
    case 5:
      if (((inc1>= 48&&inc1<= 57) || (inc1>= 65&&inc1<= 90))&&((inc2>= 48&&inc2<= 57) || (inc2>= 65&&inc2<= 80))&&((inc3>= 48&&inc3<= 57) || (inc3>= 65&&inc3<= 80))&&((inc4>= 48&&inc4<= 57) || (inc4>= 65&&inc4<= 80)))
      {
        Serial.print ("OK");
        Serial.print (inc1);
        Serial.print (":");
        Serial.print (inc2);
        Serial.print (":");
        Serial.print (inc3);
        Serial.print (":");
        Serial.print (inc4);
        Serial.print ("\ n");
        mode = 6;
        tt = 0;
        break;
      }
      else
      {
        Serial.print ("NG");
        Serial.print (inc1);
        Serial.print (":");
        Serial.print (inc2);
        Serial.print (":");
        Serial.print (inc3);
        Serial.print (":");
        Serial.print (inc4);
        Serial.print ("? Inv.data");
        Serial.print ("\ n");
        mode = 1;
        tt = 0;
        break;
      }
      break;case 6:
      inc2 = inc2-0x30;
      inc3 = inc3-0x30;
      inc4 = inc4-0x30;
      mode = 7;
      break;
    case 7:
      if (inc1 == 0x41) {
        if (inc2 == 1) {
          Mov (1, 1, 1, 1);
        }
        if (inc2 == 2) {
          Mov (2, 2, 2, 2);
        }
        if (inc2 == 3) {
          Mov (1, 2, 2, 1);
        }
        if (inc2 == 4) {
          Mov (2, 1, 1, 2);
        }
        if (inc2 == 5) {
          Mov (2, 1, 2, 1);
        }
        if (inc2 == 6) {
          Mov (1, 2, 1, 2);
        }
        if (inc3! = 0) {
          Mov (0, 0, 0, 0);
        }
      } else if (inc1 == 0x50) {
        Pwm1 = inc2 * 100 + inc3 * 10 + inc4;
      } else if (inc1 == 0x51) {
        Pwm2 = inc2 * 100 + inc3 * 10 + inc4;
      } else if (inc1 == 0x52) {
        Pwm3 = inc2 * 100 + inc3 * 10 + inc4;
      } else if (inc1 == 0x53) {
        Pwm4 = inc2 * 100 + inc3 * 10 + inc4;
      }
      mode = 1;
      break;
  }
  analogWrite (FENA, Pwm1);
  analogWrite (FENB, Pwm2);
  analogWrite (RENA, Pwm3);
  analogWrite (RENB, Pwm4);
}
// Node-MCU program
#define BLYNK_PRINT Serial

#include<ESP8266WiFi.h>
#include<BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth [] = "Type authtokun";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid [] = "WIFI name";
char pass [] = "WIFI password";
unsigned char hen [10] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39};
void setup ()
{
  // Debug console
  Serial.begin (9600);
  Blynk.begin (auth, ssid, pass);
}
BLYNK_WRITE (V10) // Slider 1 (PWM1) processing
{
  int i1, i2, i3;
  int val = param.asInt ();
  i1 = hen [val/100];
  i2 = val/100;
  i2 = val-(i2 * 100);
  i2 = hen [i2/10];
  i3 = hen [val% 10];
  Serial.print ("P");
  Serial.print (i1, 0);
  Serial.print (i2, 0);
  Serial.print (i3, 0);
}
BLYNK_WRITE (V11) // Slider 2 (PWM2) processing
{
  int i1, i2, i3;
  int val = param.asInt ();
  i1 = hen [val/100];
  i2 = val/100;
  i2 = val-(i2 * 100);
  i2 = hen [i2/10];
  i3 = hen [val% 10];
  Serial.print ("Q");
  Serial.print (i1, 0);
  Serial.print (i2, 0);
  Serial.print (i3, 0);
}
BLYNK_WRITE (V12) // Slider 3 (PWM3) processing
{
  int i1, i2, i3;
  int val = param.asInt ();
  i1 = hen [val/100];
  i2 = val/100;
  i2 = val-(i2 * 100);
  i2 = hen [i2/10];
  i3 = hen [val% 10];
  Serial.print ("R");
  Serial.print (i1, 0);Serial.print (i2, 0);
  Serial.print (i3, 0);
}
BLYNK_WRITE (V13) // Slider 4 (PWM4) processing
{
  int i1, i2, i3;
  int val = param.asInt ();
  i1 = hen [val/100];
  i2 = val/100;
  i2 = val-(i2 * 100);
  i2 = hen [i2/10];
  i3 = hen [val% 10];
  Serial.print ("S");
  Serial.print (i1, 0);
  Serial.print (i2, 0);
  Serial.print (i3, 0);
}
BLYNK_WRITE (V1) // Progress processing
{
  int val = param.asInt ();
  if (val == 1)
  {
    Serial.print ("A10B");
  }
  if (val == 0)
  {
    Serial.print ("A01B");
  }
}
BLYNK_WRITE (V3) // Backward processing
{
  int val = param.asInt ();
  if (val == 1)
  {
    Serial.print ("A20B");
  }
  if (val == 0)
  {
    Serial.print ("A02B");
  }
}
BLYNK_WRITE (V2) // Left process
{
  int val = param.asInt ();
  if (val == 1)
  {
    Serial.print ("A30B");
  }
  if (val == 0)
  {
    Serial.print ("A03B");
  }
}
BLYNK_WRITE (V4) // Right processing
{
  int val = param.asInt ();
  if (val == 1)
  {
    Serial.print ("A40B");
  }
  if (val == 0)
  {
    Serial.print ("A04B");
  }
}
BLYNK_WRITE (V5) // Left turn processing
{
  int val = param.asInt ();
  if (val == 1)
  {
    Serial.print ("A50B");
  }
  if (val == 0)
  {
    Serial.print ("A05B");
  }
}
BLYNK_WRITE (V6) // turn right
{
  int val = param.asInt ();
  if (val == 1)
  {
    Serial.print ("A60B");
  }
  if (val == 0)
  {
    Serial.print ("A06B");
  }
}
void loop () {
  Blynk.run ();
}


The Ruby program that doesn't work because of the character limit is added to the comment below.

Supplement

Using Arduino IDE 1.8.2
Http://arduino.esp8266.com/stable/package_esp8266com_index.json on ArduinoIDE
Is installed (Environment setting for Node-MCU)
Also, BLYNK custom library is included in ArduinoIDE.
The following images are settings for Node-MCU

In Rubic, the board selects GR-CITRUS, the firmware is wrbb-v2liv-firm, the revision is 2.12

  • Answer # 1

    What I always think of when I see these projects is why people make noise when they make everything suddenly
    Let's start with the basic functions.

    Porting and implementing GPIO operations
    Let's put communication and something first, and implement GPIO operations firmly. Make sure this works as intended and continue

    Implement serial communication
    GPIO should be set aside to ensure serial communication. To check the operation, let's buy a USB-serial conversion board.
    Operate the terminal software on the PC side and debug properly so that communication is performed normally.

    If you don't work before the two points above aren't working, you won't be talking.