PCB Design  

Page 8 / 8
  RSS

Robo Pi
(@robo-pi)
Robotics Engineer Moderator
Joined: 10 months ago
Posts: 1590
2020-02-15 10:40 pm  
Posted by: @dronebot-workshop

Above all I want to thank you for designing the board Robo Pi, I have one being sent to me and I'm anxious to give it a try.  The amount of work you've put into this is very impressive.

I enjoyed doing it.  I also learned a lot about KiCad in the process. ? 

I hope you don't mind that I threw the WiFi in there.  I figured that if you don't need it on DB1 it really shouldn't be in the way of anything.  Just don't attach the WiFi module.  I couldn't resist the temptation to toss it in since this is how I'm currently communicating with my robots from my PC.

I am hoping to use your motor control scheme on my robots so it will be nice to have your motor control connector available as well as the external interrupt connector. 

I'm looking at designing some more Mega Shields for my own robot designs.  I'm starting to also make a video on how I'm creating them in KiCad.  Unfortunately getting the video production techniques sorted has become a major job in and of itself.  But I'm making tons of progress on that front as well.   Plus I just ordered two condenser microphones and two USB speaker systems for my two Jetson Nanos.   They are expected to arrive on Monday.

I keep dreaming of buying a third Jetson Nano. ?  I have these two set up side-by-side and I can make videos on one of them running KiCad and a screen capture program.   Then on the other one I'm processing the videos using Kdenlive.    So I'm working double-shift here. ? 

I need a third Nano to dedicated to learning AI on the Jetson Nano with Paul McWhorter.   So I have a real good excuse to buy the third one.

And not to worry!  I watch the DroneBot Worshop episodes on a Windows 10 machine.  So that's already taken care of. ? 

DroneBot Workshop Robotics Engineer
James


ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer Moderator
Joined: 10 months ago
Posts: 1590
2020-02-17 8:35 am  

I tested the WiFi interface and it works perfectly. ? 

This is rather complicated, and not part of the DB1 project.    So I'll just offer up what I've done for whatever it might be worth.   I'm using UDP, and I'll just demonstrate this with a simple packet sending program. I actually use this with a "Robot Overseer" program written in C#, but I'm not going to get into all that here.

I'm also not going to explain how to program an ESP8266-01 modules.  You can look that up on YouTube.

What I'm going to explain here is just one-way communication from a laptop computer to the Mega Board.  Creating two-way communication is easy, but requires twice the code.  Although I currently have it set up to print results to the computer monitor if you have the Mega connected via a USB cable.

The program does the following:

  1. It turns on a small blue LED on the ESP8266 board when connected to the WiFi.
  2. It also prints this progress to the Serial monitor if a USB cable is connected.
  3. Then using a UDP packet sender, you can send commands to the ESP8266 module.
  4. These commands will allow you to turn on/off LED2 and LED3 on the new Mega Shield board.
  5. LED1 on the Mega shield will indicated incoming messages.
  6. The commands to turn on LEDs are LED2ON and LED3ON (case is unimportant)
  7. The commands to turn off LEDs are LED2OFF and LED3OFF (case is unimportant)

So let's get started. ? 

First thing you need to do is program the ESP8266 -01 board.   If you don't know how to do this, see YouTube.

Here is a the simple UDP Sketch I wrote to test the module:  You'll need to  supply your WiFi SSID and password and the IP address of your router.   Information for where to do that is in the comments of the program.

//  ESP8266 talks to WiFi and the Mega  --- VERSION 1.1 6/28/2018
//  This program uses UDP to connect to WiFi.  .
//  This connects to the Mega board using Serial port on the ESP8266 and Serial2 port on the Mega 

// Library Header for ESP8266 Commands
#include <ESP8266WiFi.h>
// Library Header for using UDP WiFi
#include <WiFiUDP.h>

// ----- Name GPIO pins -------
int Connection_LED = 2;   // The WiFi Connection Indicator LED on the ESP8266 board

// ------------ Define WiFI Connection parameters --------------
const char* ssid = "Your_WiFi_SSID_Name"; // the ssid name of your WiFi Network.
const char* password = "Your_Password"; // The password of your WiFi Network. 

// -------- Define Port, Packet_Buffer 255, and replyPacket mesage as a char array --------
WiFiUDP UDP; // Name an instance of WiFiUDP
unsigned int localUDPPort = 4210;                 // local port to listen on.  This can be changed. 
char incomingPacket[255];                         // buffer for incoming packets just set arbitrary to 255 bytes.
char  replyPacket[] = "Got the message :-)";      // a Char Array msg to send back through WiFi as a Packet. 

void setup()
{
// ------ Set up pinModes ---------
  pinMode(Connection_LED, OUTPUT);         // Connection indicator LED
  digitalWrite(Connection_LED, LOW);      // turn OFF the indicator to start 

// ------ BEGIN Serial communication with Arduino Mega 
  
  Serial.begin(9600);                           // Set the BAUD rate to 9600
  Serial.println();                             // Just sends a line feed.
  Serial.printf("Connecting to %s ", ssid);     // Message "Connecting to Your_WiFi_Name"

// ------------ BEGIN Setup WiFI Connection --------------

// ------- Set up the WiFi  ----------
// Select a static IP for your robot.  You're choice.  The following is just an example:
IPAddress ESP_IP(192,168,1,42);    //Static IP address - you may want to change this. 

// The following should be your info for your WiFi router and Network. 
IPAddress Router_IP(192,168,1,1);    // IP address for your Wifi router (may be different than this example)
IPAddress subnet(255,255,255,0);      // subnet mask
WiFi.config(ESP_IP,Router_IP,subnet); // This command then sets up the configuration 
// ------- END setting static IP address for the ESP8266 ----------

// ---- Begin the actual connection ---------
  WiFi.begin(ssid, password);             

// ---- Wait until connected ---------
  while (WiFi.status() != WL_CONNECTED)   
  {
    delay(500);
    Serial.print("."); // prints dots while connecting.
  }
// ------------ END Setup WiFI Connection --------------
// (NOTE: The program will never leave the above while loop if no connection is made ----

  
  // UDP connection has been made
  Serial.println(" connected"); // prints to serial monitor if Mega is connected via USB cable. 
  digitalWrite(Connection_LED, LOW);   // turn the connection LED ON (active low)
  
  // Begin to listen to the UDP Port
  UDP.begin(localUDPPort);
  Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUDPPort);
} //  ------- END void setup()



void loop()
{

// ----------- BEGIN --- Receive incoming UDP packets -------------
  int packetSize = UDP.parsePacket();
  if (packetSize)  // if packetSize is > 0 do the following:
  {  
    int len = UDP.read(incomingPacket, 255);  // get the length of the incoming packet. 
    if (len > 0)                              // If greater than zero something must have come in.
    {
      Serial.println(incomingPacket);          // Send  the incoming character array to the serial port.
      for(int i=0;i<255;i++) incomingPacket[i] = 0; // Clear the packet buffer
      len = 0;                // reset len to 0
      
    }

// BEGIN --------- send back a reply, to the IP address and port we got the packet from
    UDP.beginPacket(UDP.remoteIP(), UDP.remotePort());    // Set-up to send the packet.
    UDP.write(replyPacket);                               // replyPacket is the message defined at top of program. 
    UDP.endPacket();                                      // End the transmission after having sent the reply. 
  }  // ----------- END Receive incoming UDP packets -------------
} // END void loop()


// This is the end of the program.

// The program basically does the following:
// 1. Sets up LED on pin 2 of the ESP8266 module to be a connection indicator.
// 2. It then reads any incoming packets (it's constantly monitoring the UDP connection),...
// 3. This program then sends the incoming packet over to the Mega using Serial.print(incomingPacket)
// 4. This program currently does not look for any return message coming back from the Mega. (To be done later)

After you have the ESP8266-01 module programmed you'll need to program the Mega board to receive the serial messages coming from the ESP8266 modules.  These will come in on Serial2.   This program also turns the LEDs on the Mega shield on and off.

 

// For File Signature info: -----
#define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
// --------- #import statements go here.
// -------- Then global variables. 

String message_Keep;
String message_ESP;
int LED1 = 10;
int LED2 = 11;
int LED3 = 12;
int SW1 = 9;
int SW2 = 8;

void setup() {
  // ----- Begin File Signature ----
  Serial.begin(9600);
  Serial.print("Source filename: ");
  Serial.println(__FILENAME__); // Source file name
  Serial.print("Compile date: ");
  Serial.println(__DATE__);
  Serial.print("Compile time: ");
  Serial.println(__TIME__);
  Serial.print("File Location: ");
  Serial.println(__FILE__); // prints the full path
  Serial.println("--------- Notes: ESP8266 WiFI TEST ---------");
  Serial.println("");
  // ----- END  File Signature ----

  // Setup LED pins
  pinMode (LED1,OUTPUT);
  pinMode (LED2,OUTPUT);
  pinMode (LED3,OUTPUT);
  // Switches are here to play with later. 
  pinMode (SW1,INPUT);
  pinMode (SW2,INPUT);
  // Turn off all LEDS to start. 
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  // start serial2 communication at 9600bps for ESP8266
  // be sure to use the same baud rate programmed at the ESP end. 
  Serial2.begin(9600);  
}

void loop(){

// ----------- Look to see if there is a message from the ESP8266 ----------
// ----------- If there is print it to the Serial Monitor ----
  if (Serial2.available() > 0) 
  {   
    digitalWrite(LED1, HIGH); // Turn on LED1 to show a msg coming in. 
    // Read the message as a string.
    message_ESP = Serial2.readString();
    message_Keep = message_ESP.substring(0,message_ESP.length()-2); // strip off carrage return.
    // Echo the received message back to the serial monitor (if hardwired)
    Serial.println("Message from ESP8266: ");
    Serial.println(message_ESP);
    delay(2000); // wait 2 seconds just for fun.
    digitalWrite(LED1, LOW); // Turn LED1 back off after message received. 
  }

  // the following if statments turn on or off LED2 and LED3
  // this commands must be sent to the ESP WiFi module via UDP. 
  if (message_Keep.equalsIgnoreCase("LED2ON"))
  {
    digitalWrite(LED2, HIGH);  
  }
  if (message_Keep.equalsIgnoreCase("LED3ON"))
  {
    digitalWrite(LED3, HIGH);  
  }
  if (message_Keep.equalsIgnoreCase("LED2OFF"))
  {
    digitalWrite(LED2, LOW);  
  }
  if (message_Keep.equalsIgnoreCase("LED3OFF"))
  {
    digitalWrite(LED3, LOW);  
  }  
} 

Finally, you'll need a UDP packet sender.  You can download a free Packet Sender here:

Packet Sender

If you manage to do all of the above, you should be able to send commands to the ESP8266 module and have them passed through to the Mega board via Serial2. 

The commands are:

LED2ON, LED2OFF, LED3ON, and LED3OFF.  (not case sensitive).

Every time you send a command to the ESP8266 you should get a packet back saying: "Got the messsage!" with a little smilely face after it. 🙂

These commands should turn the respective LEDs on and off on the Arduino Shield.

If you have the Mega connected to the compouter via a USB cable you will also get messages sent to the Serial Monitor there.  But you don't need to have the USB  cable connected.  You can now disconnect the Mega board (give it battery power)  and you should then be able to control the LEDs on the Shield via just the WiFi command.

Yes, it's a very simple demonstration, but unlimited in scope.  You can also add two-way communication if you want to send information from the Mega to the Packet Sending program.

This is just for test purposes.  Obviously the real power is when you write your own program on your laptop instead of using the Packet Sender.

And that's all I have to say about that.

Enjoy! ? 

 

 

DroneBot Workshop Robotics Engineer
James


ReplyQuote
Michael T
(@michael-t)
Active Member
Joined: 10 months ago
Posts: 11
2020-02-24 3:14 am  

@huckohio

Hi Mike --

I'm much interested in ordering some more of these boards, and understand from Mr. Pi that you have the necessary files for manufacture.  Would it be possible for you to send me a copy of the Gerber files, and let me know from whom you ordered the first batch?  As was your original plan, I only need a couple of boards for my own use, and would be delighted to make the few leftovers available to anyone interested. 

Many thanks.

Michael T

 

This post was modified 1 month ago by Michael T

ReplyQuote
huckOhio
(@huckohio)
Eminent Member
Joined: 7 months ago
Posts: 37
2020-02-24 11:22 am  

@michael-t

Absolutely.  Send me a message with your email and I will send then out later today.


ReplyQuote
Michael T
(@michael-t)
Active Member
Joined: 10 months ago
Posts: 11
2020-02-24 11:35 pm  

PM received with thanks, but it seems I'm not set up to reply to it.  Also the files didn't make it through.  My e-mail:  jagrolet8@gmail.com.  Thanks again.  


ReplyQuote
huckOhio
(@huckohio)
Eminent Member
Joined: 7 months ago
Posts: 37
2020-02-25 12:52 am  

@michael-t

Just sent the files.  

Mike


ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 10 months ago
Posts: 507
2020-02-25 5:37 pm  

@michael-t

You have only made 8 posts so you don't have the ability to to use the PM feature, and when @huckohio tried to send you a file, it also failed because you haven't reached the magic number 10 yet.

Reply to my post and you'll be up to 9.  Only one more after that.  Maybe reply to huchohio's post where he let you know he was sending via your supplied email, then you would have 10.

SteveG


ReplyQuote
Michael T
(@michael-t)
Active Member
Joined: 10 months ago
Posts: 11
2020-02-25 11:46 pm  

@codecage

Got it.  Many thanks.  I shoulda read the rules.

 

 


ReplyQuote
Michael T
(@michael-t)
Active Member
Joined: 10 months ago
Posts: 11
2020-02-26 12:54 am  

@huckohio

Thanks Mike, files received.  I checked out the pcbway site and they need some basic specs before I can send the files and proceed with the order:  dimensions, number of layers, thickness? I'd like to duplicate your order as accurately as possible....could you advise?


ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 10 months ago
Posts: 507
2020-02-26 12:57 am  

@michael-t

Easily over looked!

SteveG


ReplyQuote
Michael T
(@michael-t)
Active Member
Joined: 10 months ago
Posts: 11
2020-03-11 2:20 am  

I've just received a little batch of these Robo-Pi-designed Shield boards from PCBWay.  I haven't populated (so not tested) one yet, but they're made from the same Gerber files as the original.  If anyone is interested in procuring one, just PM me with a request and a mailing address.

Michael T


ReplyQuote
Page 8 / 8

Please Login or Register