Go Down

Topic: Standalone Arduino Serial debug not working (Read 2063 times) previous topic - next topic

bule

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?

Robin2

Post your code. In code tags please. Hope it is not too long.

Check your baud rates.

...R

bule

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);
}

bule

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.

Robin2

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


MAS3

How and at what speed is your atmega clocked on that custom board ?
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

bule

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..

MAS3

I'll repeat myself:
Did you connect the grounds (GND) ?
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

bule

Yes, I take power from pcb for max232 serial to ttl.
So +5V and GND are same.

Docedison

#9
Feb 08, 2014, 11:40 pm Last Edit: Feb 08, 2014, 11:42 pm by Docedison Reason: 1
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
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Robin2


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

bule

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.

bule

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

Robin2

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

bule

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..

Go Up