Arduino Forum

Using Arduino => Microcontrollers => Topic started by: bule on Feb 08, 2014, 07:35 pm

Title: Standalone Arduino Serial debug not working
Post by: bule on Feb 08, 2014, 07:35 pm
Hi guys,
I create GSM controled arduino with GSM 2 Click (form Mikroelektronika) and its working ok when Atmega 328p is in arduino board.
But when I put atmega in custom board its its working but  I have some problems with communication with GSM, so I try to connect arduino board w/o atmega to see serial print on pin 0 and 1. But all I get is some artefacts in serial window.
What do I do wrong?
Title: Re: Standalone Arduino Serial debug not working
Post by: Robin2 on Feb 08, 2014, 07:44 pm
Post your code. In code tags please. Hope it is not too long.

Check your baud rates.

...R
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 08, 2014, 09:32 pm
Again, everything is working on arduino board including serial, but when I transfer atmega to custom board it's working but I can't check serial communicatiom over RX TX (pin 0 and pin 1).
Here is my code:
Code: [Select]

#include <EEPROM.h>
#include <GSM.h> // include the GSM library
#define PINNUMBER "" // PIN Number for the SIM
GSM gsmAccess; // initialize the library instances
GSM_SMS sms;
#define gsm 9 // define pin for startup gsm
int addr = 0; // EEPROM address for storing pin state
unsigned char pins;
void setup()
{
  // restore the lights
  pins = EEPROM.read (addr);
  for (int i=A0; i<A4; i++) {
    digitalWrite(i, bitRead(pins, i-A0));
  }
  gsmOn(); //power up GSM
  Serial.begin(9600);  // initialize serial communications and wait for port to open:
  //while (!Serial) {
  // ; // wait for serial port to connect. Needed for Leonardo only
  //}
  Serial.println(F("SMS Messages Receiver"));
  // connection state
  boolean notConnected = true;
  // Start GSM connection
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println(F("Not connected"));
      delay(1000);
    }
  }
  sms.flush();  // delete all messages
  Serial.println(F("GSM initialized"));
  Serial.println(F("Waiting for messages"));
  showFlags();
}
void loop()
{
 
  // If there are any SMSs available()
  if (sms.available())
  {
    RelaySMS();
    sms.flush();
    //Serial.println("MESSAGE DELETED");
  }
  delay(1000);
}
void gsmOn() // Power up gsm
{
  digitalWrite(gsm, HIGH);
  delay(1000);
  digitalWrite(gsm, LOW);
  delay(5000);
}
void RelaySMS()
{
  char c;
  c=sms.read();         // read sms
  if (c=='1')         // If first sign is 1 do next:
  {
    txt(A3,A3);
  }
  else if (c=='2')
  {
    txt(A2,A2);
  }
  else if (c=='3')
  {
    txt(A1,A1);
  }
  else if (c=='4')
  {
    txt(A0,A0);
  }
}
void txt(int Relay, int pin)
{
  pinMode(Relay, OUTPUT);
  Relay = pin;
  String txtmsg = "";
  char c;
  char remoteNumber[10];
  while(c=sms.read())
    txtmsg += c;
  Serial.println(F("Sadrzaj sms-a:")); //SMS text
  Serial.println(txtmsg);
  if (txtmsg.compareTo("on") == 0)
  {
    if (digitalRead(Relay) == HIGH){
    }
    else if (digitalRead(Relay) == LOW){
      digitalWrite(Relay, HIGH);
      save_pin(Relay); //save to eeprom
    }
  }
  else if (txtmsg.compareTo("off") == 0)
  {
    if (digitalRead(Relay) == LOW){
    }
    else if (digitalRead(Relay) == HIGH){
      digitalWrite(Relay, LOW);
      save_pin(Relay); //save to eeprom
    }
  }
  else if (txtmsg.compareTo("status") == 0)
  {
    /*String statustxt = "";
     pinstate = digitalRead(pin);
     if (pinstate == 1){
     sms.remoteNumber(remoteNumber, 10);
     sms.beginSMS(remoteNumber);
     sms.print(statustxt);
     sms.endSMS();
     }
     */
  }
}
/*void allstatustxt ()
{
int pinstate;
String statustxt = "";
pinstate = digitalRead(pin);
if (pinstate == 1){



sms.remoteNumber(remoteNumber, 10);
sms.beginSMS(remoteNumber);
sms.print(pinstate);
sms.endSMS();
}
}
*/
void save_pin (byte pin) // Save pin to EEPROM
{
  pins = EEPROM.read (addr) ;
  bitWrite (pins, pin - A0, digitalRead(pin)) ;  //assuming A0 is stored in bit 0
  EEPROM.write(addr, pins);
}
void showFlags()  // Only to control byte variable that is stored to EEPROM
{
  for(int flag=0; flag < 8; flag++)
  {
    if (bitRead(pins, flag) == true)
    Serial.println(F("Flagovi su sledeci:"));
    Serial.println(pins);
  }
  Serial.println();
}
int getFlag( int flagNumber) // Only to control byte variable that is stored to EEPROM
{
  return bitRead(pins, flagNumber);
}
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 08, 2014, 09:33 pm
I use arduino board (for serial connection)to connect to custom board, Only difference is that I didn't put 1K resistor on RX and TX line.
Title: Re: Standalone Arduino Serial debug not working
Post by: Robin2 on Feb 08, 2014, 10:27 pm
You have a line
Code: [Select]
Serial.println(F("SMS Messages Receiver"));

Does that work?

If it does, explain more exactly what does not work.

If it doesn't, just make a short sketch with just that in it and get that working before moving to something more complex.

...R

Title: Re: Standalone Arduino Serial debug not working
Post by: MAS3 on Feb 08, 2014, 10:41 pm
How and at what speed is your atmega clocked on that custom board ?
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 08, 2014, 10:58 pm
All I get from terminal is: ?p?|p
Nothing print on serial port. Clock is 16MHz and I build custom board on schematic from arduino. I know it's working because it turn on test LED on A0,A1,A2,A3 pinout.
On arduino board my program is working very well. But on my pcb I dont recieve sms. So I try to listen serial port to see what could be the problem.
And there is another problem... Serial print not working..
Title: Re: Standalone Arduino Serial debug not working
Post by: MAS3 on Feb 08, 2014, 11:21 pm
I'll repeat myself:
Did you connect the grounds (GND) ?
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 08, 2014, 11:25 pm
Yes, I take power from pcb for max232 serial to ttl.
So +5V and GND are same.
Title: Re: Standalone Arduino Serial debug not working
Post by: Docedison on Feb 08, 2014, 11:40 pm
The Next Question is in regard to the NECESSARY bypassing... .1uF caps are cheap... Is your time so valueless that five cents is more valuable?..
ALL OF THE PARTS ON ANY ARDUINO BOARD ARE THE ABSOLUTE MINIMUM REQUIRED TO CAUSE THE CIRCUIT/CONTROLLER TO WORK AS IT SHOULD. NONE  Should ever be left out...
To do so is to indicate that you know more than the designer did... So that being the case where is the issue?.
While this might not apply directly to your case it is applicable to many others and perhaps food for thought for you..
The other very common issue IS batteries. The Minimum recommended is 3 AA cells applied to Vcc (Not 4). This will provide 4.25V to the controller and is a good beginning If you can't use the USB connection for power.
Best in my Direct experience is a SMPS 7.5V "Wall Wart" as it will allow the linear regulator to work better within it's specifications.
Consider that a 9V external PSU is 9/7.5 or 20% more power Wasted as heat in the regulator and a 12V external PSU is 12/7.5 or 60% more Wasted Power in the linear regulator. Food for thought?

Doc
Title: Re: Standalone Arduino Serial debug not working
Post by: Robin2 on Feb 09, 2014, 10:00 am

All I get from terminal is: ?p?|p
...SNIP...

And there is another problem... Serial print not working..


What should have appeared on the terminal instead of "?p...."  ?

Did you try my earlier suggestion of writing a very short sketch to make sure Serial.print is working?

If you are to solve any sort of computer problem you need to focus your investigations as narrowly as possible. It's just a waste of time wondering what is wrong if there can be more than one culprit.

...R
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 09, 2014, 11:36 am
On serial should write for start:
Code: [Select]
Serial.println(F("SMS Messages Receiver"));
As I say again I think it's not problem about code but hardware issue, because everything is working when atmega is on arduino duemilanove board.
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 09, 2014, 11:38 am
I try to find out if I did something wrong in my pcb.
But when I see on arduino site how to make arduino on breadboard and how to communicate with it, It is the same as I did.
But I cant get communication working
Title: Re: Standalone Arduino Serial debug not working
Post by: Robin2 on Feb 09, 2014, 01:36 pm
I did not mean to imply that you have a software rather than a hardware problem.

Whichever sort of problem it is it will be much easier to figure out with a really short sketch.

Writing a short sketch that does nothing but print a short message will take you 5 or 10 minutes. Then try that on your two processors and come back with your results.

...R
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 09, 2014, 02:41 pm
I listen to you and I created small code:
Code: [Select]

void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);           // set up Serial library at 9600 bps
 
  Serial.println("Hello world!");  // prints hello with ending line break
}

void loop()                       // run over and over again
{
                                  // do nothing!
}

And connected Rx (pin 0 duemilanove w/o atmega) to Rx (PD2 to atmega) and Tx (pin 1 duemilanove w/o atmega) to Tx (PD1 to atmega) .
And guess what...
I still get garbage from serial terminal..
Title: Re: Standalone Arduino Serial debug not working
Post by: Robin2 on Feb 09, 2014, 05:07 pm
OK, now we are making progress by getting all the distractions out of the way.

Next thing is to look closely at the wiring arrangements. Can you post a diagram of what you have done. A photograph of a drawing will be fine.

...R
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 09, 2014, 09:25 pm
Here is the schematic picture of my project..
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 09, 2014, 09:34 pm
Entire shematic
Title: Re: Standalone Arduino Serial debug not working
Post by: Robin2 on Feb 09, 2014, 10:15 pm
Why aren't you using the normal Rx and Tx pins? They are what Serial.print() outputs on.

How are the Rx and Tx lines connected to whatever serial monitor you are using? That arrangement is missing from your drawing.

...R
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 09, 2014, 11:26 pm
I dont use normal rx and tx because gsm library use software serial. And in arduino duemilanove ft232 use real atmega hardware serial for upload and monitor serial output
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 09, 2014, 11:28 pm
Nothing is missing on schematic. On the right side only is connectors for gsm click 2
Title: Re: Standalone Arduino Serial debug not working
Post by: MAS3 on Feb 10, 2014, 12:40 am

...And connected Rx (pin 0 duemilanove w/o atmega) to Rx (PD2 to atmega) and Tx (pin 1 duemilanove w/o atmega) to Tx (PD1 to atmega) .


Have another look to confirm you actually did wire up like this.
If you did, then this is where your error is.
I can't tell whether the functions of the pins are as you stated in your implementation of software serial (and i don't understand why you need to do this, but that aside).
But you are saying you connected the receive to receive and transmit to transmit.
How do you think you will receive any signal that is not transmitted (because a receiver doesn't transmit) ?

By the way, there is something missing in your schematics.
Where is the second controller ?
And where is the connection we are trying to debug at the moment ?
An outgoing arrow with a label is not a connection if there is no incoming arrow that has the same label.
As for this, i can see something (to my taste incorrect drawn) that looks like a connection, on that right side going to your GSM.
Which means it can't go to some other device.

Show us a new drawing or a clear photograph where you show how you have wired up your setup (so not how you are supposed to wire it, but how it is actually wired).
Title: Re: Standalone Arduino Serial debug not working
Post by: Robin2 on Feb 10, 2014, 10:57 am

I dont use normal rx and tx because gsm library use software serial. And in arduino duemilanove ft232 use real atmega hardware serial for upload and monitor serial output


In Reply #14 you said you are getting garbage with "Serial.println("Hello world!");".

Serial.println() uses the standard Rx and Tx pins.

So a better explanation of what is going on is needed if you are to get any useful advice.

And you didn't answer my question about how the data gets to your serial monitor.

...R
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 10, 2014, 07:38 pm
First of all.. I put back atmega on arduino duemilanove board and serial print work on serial monitor.
Next I connect another MAX232N on Pin0 and Pin 1, and again everything work.
But when I put atmega on my pcb I get garbage on serial monitor. Here is picture of my test pcb.
I start to think that there is problem with my pcb.
Title: Re: Standalone Arduino Serial debug not working
Post by: Robin2 on Feb 10, 2014, 09:26 pm
I'm sorry but your 2 line description and your pictures are meaningless to me. You were asked earlier for a full wiring diagram but you haven't provided one. And the one you did provide doesn't include all the stuff in the photos.

I have asked you several specific questions and you haven't given any understandable replies.

How am I supposed to help?

If it helps, think of me as a ridiculously stupid person who needs every little detail carefully explained.

I reckon I'm reasonably good at debugging. But you need to give me stuff I can work with. And debugging is a tediously systematic process - that's just how it is.

...R
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 10, 2014, 10:05 pm
Robin2 I am very sorry for my crazy posts, This kind of stupid problem drive me crazy. I am not an expert for electronic but I have a very large will to learn.
Can you please repeat the questions so I can answer you the most exactly.
Title: Re: Standalone Arduino Serial debug not working
Post by: MAS3 on Feb 10, 2014, 10:32 pm
Wait a minute.
How many max232's are in your setup (meaning both boards) ?
Doesn't a max232 invert the signals ?
And i'm also curious why you need this part.

Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 10, 2014, 11:10 pm
I only have one max232.
Yes, max232 inverts ttl signal to serial for pc.
I need this part because on my pcb I only have AVR ISP for programming and I dont know what is goin' on with my code.
So I solder two wires (RX - TX) directly from my serial max232 to ttl converter to atmega. This is some kind of low cost debuging.
This is my first complex project in arduino.
I will draw block schematic and post it what exactly am I doing.
Title: Re: Standalone Arduino Serial debug not working
Post by: MAS3 on Feb 10, 2014, 11:21 pm
Make sure to write the max232 pin numbers you are connecting your wires to in that schematic too.
We need to know whether you are connecting to the input pins or the output pins of that max232, for this temporary debug setup.
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 10, 2014, 11:43 pm
Here are my images
Title: Re: Standalone Arduino Serial debug not working
Post by: Robin2 on Feb 10, 2014, 11:55 pm

Can you please repeat the questions so I can answer you the most exactly.


No !

...R
Title: Re: Standalone Arduino Serial debug not working
Post by: MAS3 on Feb 11, 2014, 12:11 am
It seems to be hard to show us exactly what you've built.
(the new pic shows 2 max232 and 1 pin layout for dip 16 like your max232)
We're guessing here, and that makes it hard to tell we're actually helping, or making things worse for you.

So, you've connected max232 pin 11 (ttl tx) to (remote) ATMega rx, and max232 pin 12 (ttl rx) to (remote) ATMega tx ?
Where (what pins of both) is your local ATMega connected to the max232 ?

Don't despair, just take some time to show how tings are right now.
And as Robin2 already explained,  assume we don't know anything about that yet so put all in it.
Title: Re: Standalone Arduino Serial debug not working
Post by: bule on Feb 11, 2014, 12:19 am
Quote
So, you've connected max232 pin 11 (ttl tx) to (remote) ATMega rx, and max232 pin 12 (ttl rx) to (remote) ATMega tx ?

Yes that is how I connected.
There is no connection (max232 ttl to atmega)on schematic because I dont need it, but I soldered directly on atmega pin 2 and 3.
Title: Re: Standalone Arduino Serial debug not working
Post by: MAS3 on Feb 11, 2014, 12:49 am
You do not seem to understand what (and why) schematics are.

There is a difference between schematics and wiring.
Wiring is about how to connect modules to each other.
These modules are probably mounted on pcb's.

Schematics show how all components are connected, so also the connections on a pcb.

You telling us that you do not need a connection between max232 and the ATMega on the same board (i'm guessing that is what you just did), tells me you don't understand the importance of schematics for debugging, and what schematics actually show yet.
You soldered pin 2 and 3 of an ATMega directly, but what ATMega would that be and where are the other sides of those wires connected ?
Showing the actual schematic would have made this question unnecessary, but now i still don't know what is connected to what.

So, still guessing this is what you want, and still creating confusion:
Did you connect pin 2 of one ATMega to pin 3 of the other one, and pin 3 to pin 2 (do you understand what i'm asking ?) ?

Edit: typos and clarification
Title: Re: Standalone Arduino Serial debug not working
Post by: spycatcher2k on Feb 11, 2014, 04:41 pm
I can't see if this has been asked - Is your Terminal/Serial Monitor set to the correct speed, stop bits etc. ?