Can't telnet my arduino Mega.

Hi, I’ve been testing my arduino, trying to telnet it for 2 hours now. lol.

Can you please help me? It’s kinda frustrating. I use Adafruit CC3000 wifi shield to connect my arduino to my router.

Here are my two result:

  1. baudrate 115200

  2. baudrate 9600

/***************************************************
Adafruit CC3000 Breakout/Shield TCP Chat Server
This is a simple chat server which allows clients to connect
with telnet and exchange messages. Anything sent by one
client will be written out to all connected clients.
See the CC3000 tutorial on Adafruit's learning system
for more information on setting up and using the
CC3000:
http://learn.adafruit.com/adafruit-cc3000-wifi
Requirements:
This sketch requires the Adafruit CC3000 library. You can
download the library from:
https://github.com/adafruit/Adafruit_CC3000_Library
For information on installing libraries in the Arduino IDE
see this page:
http://arduino.cc/en/Guide/Libraries
Usage:
Update the SSID and, if necessary, the CC3000 hardware pin
information below, then run the sketch and check the
output of the serial port. After connecting to the
wireless network successfully the sketch will output
the IP address of the server and start listening for
connections. Once listening for connections, connect
to the server from your computer using a telnet client
on port 23.
For example on Linux or Mac OSX, if your CC3000 has an
IP address 192.168.1.100 you would execute in a command
window:
telnet 192.168.1.100 23
Connect multiple clients and notice that whatever one client
sends will be echoed to all other clients. Press ctrl-] and
type quit at the prompt to close the telnet session.
On Windows you'll need to download a telnet client. PuTTY
is a good, free GUI client:
http://www.chiark.greenend.org.uk/~sgtatham/putty/
License:
This example is copyright (c) 2013 Tony DiCola (tony@tonydicola.com)
and is released under an open source MIT license. See details at:
http://opensource.org/licenses/MIT
This code was adapted from Adafruit CC3000 library example
code which has the following license:
Designed specifically to work with the Adafruit WiFi products:
----> https://www.adafruit.com/products/1469
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "utility/debug.h"
#include "utility/socket.h"
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIVIDER); // you can change this clock speed
#define WLAN_SSID "marshmallows" // cannot be longer than 32 characters!
#define WLAN_PASS "Yanabels82190"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY WLAN_SEC_WPA2
#define LISTEN_PORT 23 // What TCP port to listen on for connections.
Adafruit_CC3000_Server chatServer(LISTEN_PORT);
void setup(void)
{
Serial.begin(115200);
Serial.println(F("Hello, CC3000!\n"));
Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
/* Initialise the module */
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected!"));
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
{
delay(100); // ToDo: Insert a DHCP timeout!
}
/* Display the IP address DNS, Gateway, etc. */
while (! displayConnectionDetails()) {
delay(1000);
}
/*********************************************************/
/* You can safely remove this to save some flash memory! */
/*********************************************************/
Serial.println(F("\r\nNOTE: This sketch may cause problems with other sketches"));
Serial.println(F("since the .disconnect() function is never called, so the"));
Serial.println(F("AP may refuse connection requests from the CC3000 until a"));
Serial.println(F("timeout period passes. This is normal behaviour since"));
Serial.println(F("there isn't an obvious moment to disconnect with a server.\r\n"));
// Start listening for connections
chatServer.begin();
Serial.println(F("Listening for connections..."));
}
void loop(void)
{
// Try to get a client which is connected.
Adafruit_CC3000_ClientRef client = chatServer.available();
if (client) {
// Check if there is data available to read.
if (client.available() > 0) {
// Read a byte and write it to all clients.
uint8_t ch = client.read();
chatServer.write(ch);
}
}
}
/**************************************************************************/
/*!
@brief Tries to read the IP address and other connection details
*/
/**************************************************************************/
bool displayConnectionDetails(void)
{
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
Serial.println(F("Unable to retrieve the IP Address!\r\n"));
return false;
}
else
{
Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
Serial.println();
return true;
}
}

Same result for the two baudrates.
You see, if I enter even 1 character in PuTTy, it becomes inactive and the serial monitor or the other putty acting as serial monitor will display HELLO CC3000 again, initializing… :((

Anyone?
I will use telnet instead of TCP/UDP to connect it to C#. This would be my last bet. 2:20AM here.

I can't see your code from here. Here is mine for the ethernet shield. http://playground.arduino.cc/Code/Telnet

Hi timmy,

Here is my code:

/***************************************************
Adafruit CC3000 Breakout/Shield TCP Chat Server
This is a simple chat server which allows clients to connect
with telnet and exchange messages. Anything sent by one
client will be written out to all connected clients.
See the CC3000 tutorial on Adafruit's learning system
for more information on setting up and using the
CC3000:
http://learn.adafruit.com/adafruit-cc3000-wifi
Requirements:
This sketch requires the Adafruit CC3000 library. You can
download the library from:
https://github.com/adafruit/Adafruit_CC3000_Library
For information on installing libraries in the Arduino IDE
see this page:
http://arduino.cc/en/Guide/Libraries
Usage:
Update the SSID and, if necessary, the CC3000 hardware pin
information below, then run the sketch and check the
output of the serial port. After connecting to the
wireless network successfully the sketch will output
the IP address of the server and start listening for
connections. Once listening for connections, connect
to the server from your computer using a telnet client
on port 23.
For example on Linux or Mac OSX, if your CC3000 has an
IP address 192.168.1.100 you would execute in a command
window:
telnet 192.168.1.100 23
Connect multiple clients and notice that whatever one client
sends will be echoed to all other clients. Press ctrl-] and
type quit at the prompt to close the telnet session.
On Windows you'll need to download a telnet client. PuTTY
is a good, free GUI client:
http://www.chiark.greenend.org.uk/~sgtatham/putty/
License:
This example is copyright (c) 2013 Tony DiCola (tony@tonydicola.com)
and is released under an open source MIT license. See details at:
http://opensource.org/licenses/MIT
This code was adapted from Adafruit CC3000 library example
code which has the following license:
Designed specifically to work with the Adafruit WiFi products:
----> https://www.adafruit.com/products/1469
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "utility/debug.h"
#include "utility/socket.h"
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIVIDER); // you can change this clock speed
#define WLAN_SSID "marshmallows" // cannot be longer than 32 characters!
#define WLAN_PASS "Yanabels82190"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY WLAN_SEC_WPA2
#define LISTEN_PORT 23 // What TCP port to listen on for connections.
Adafruit_CC3000_Server chatServer(LISTEN_PORT);
void setup(void)
{
Serial.begin(115200);
Serial.println(F("Hello, CC3000!\n"));
Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
/* Initialise the module */
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected!"));
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
{
delay(100); // ToDo: Insert a DHCP timeout!
}
/* Display the IP address DNS, Gateway, etc. */
while (! displayConnectionDetails()) {
delay(1000);
}
/*********************************************************/
/* You can safely remove this to save some flash memory! */
/*********************************************************/
Serial.println(F("\r\nNOTE: This sketch may cause problems with other sketches"));
Serial.println(F("since the .disconnect() function is never called, so the"));
Serial.println(F("AP may refuse connection requests from the CC3000 until a"));
Serial.println(F("timeout period passes. This is normal behaviour since"));
Serial.println(F("there isn't an obvious moment to disconnect with a server.\r\n"));
// Start listening for connections
chatServer.begin();
Serial.println(F("Listening for connections..."));
}
void loop(void)
{
// Try to get a client which is connected.
Adafruit_CC3000_ClientRef client = chatServer.available();
if (client) {
// Check if there is data available to read.
if (client.available() > 0) {
// Read a byte and write it to all clients.
uint8_t ch = client.read();
chatServer.write(ch);
}
}
}
/**************************************************************************/
/*!
@brief Tries to read the IP address and other connection details
*/
/**************************************************************************/
bool displayConnectionDetails(void)
{
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
Serial.println(F("Unable to retrieve the IP Address!\r\n"));
return false;
}
else
{
Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
Serial.println();
return true;
}
}

Again, I use CC3000 Adafruit wifi shield to telnet the arduino.
question: to telnet the arduino, what port should I use? I used port 23, is this correct? or should I use 80?
As you can see in my screenshot, the arduino receives nothing from the telnet client(my laptop itself). stressful.
I’m hoping that using telnet will be as fast as serial. TY

Port 23 should be good for telnet. That appears that is the port the sketch you posted is listening to.

Ok thanks. Can you check my two screenshots sir Timmy? Upon entering the IP ADDRESS of the arduino+CC3000 in my putty and port 23 and clicking the OPEN BUTTON, the putty-telnet will come up but wihout any message, and if I press any key, the terminal or the Serial monitor of the Arduino+cc3000 will refresh, meaning will go to the start again, initializing and requesting DHCP :(

up^

I don't have a CC3000 to test anything with. Have you tried writing to just the one client?

// Read a byte and write it to the sending client.
uint8_t ch = client.read();
client.write(ch);

edit: Those displays look the same to me, except the way the two programs handle a '\n' character. If you want them to look the same, add a '\r', like this:

Serial.print(F("\r\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
Serial.print(F("\r\nNetmask: ")); cc3000.printIPdotsRev(netmask);
Serial.print(F("\r\nGateway: ")); cc3000.printIPdotsRev(gateway);
Serial.print(F("\r\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
Serial.print(F("\r\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);[\code]

and if I press any key, the terminal or the Serial monitor of the Arduino+cc3000 will refresh, meaning will go to the start again, initializing and requesting DHCP

This normally indicates you have either run out of SRAM, the code is overflowing an array, or assigning something to a variable that does not have a memory allocation.

Hi mr. Timmy, I HAVE MADE IT WORK! :slight_smile: My CC3000 shield’s firmware was upgraded. At first I upgraded it to its latest firmwar 1.14? and then it didn’t work. I was scared lol. Thought it damaged the chip or something, and then downgraded it and then uploaded the latest firmware again. and it worked!

I can now use telnet. I’m loving this telnet. Telnet is like serial, right? I mean I can control my components, like motors in arduino via wifi in real time, right? Now, I just have to modify my C# program.
The one and only minor error that I’m getting is that the first time you send a byte to the arduino mega via telnet, the arduino mega receives special characters first plus the sent byte.

example: you send ‘ABC’. It you will print it to the serial monitor, it will go like this: ¼ï↨╫ABC. and then the second and so on time, it goes fine. :slight_smile: But I think I can solve that easily in my C# program, like: upon connecting the C# program to the arduino via telnet, the program will send random byte immediately to clear out the error. :slight_smile:

Glenn (happy lol). thanks.

glenn_boy13, Are you from the Philippines?

glenn_boy13 How you upgrade the firmware of the cc3000 adafruit?