Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Networking, Protocols, and Devices / Re: RS485 protocol problem on: June 29, 2014, 02:49:37 pm
New updates...
It's working  with arduino (atmega328p).
But not working with atmega8.
I dont understand library very well.
How to send command to turn pin high?
2  Using Arduino / Networking, Protocols, and Devices / Re: RS485 protocol problem on: June 27, 2014, 01:18:00 am
Quote
Have you tried a real Arduino as the master and slave?

No I didnt. Yet. I get yesterday brand new atmega328p so I will burn I try this during weekend.
I'll get back tou you..
3  Using Arduino / Networking, Protocols, and Devices / Re: RS485 protocol problem on: June 26, 2014, 02:12:40 pm
Well I see it's not working beacause noting is happen on slave atmega8 side.
And on master atmega8 side led (pin 13) is ON probably because this line:

Code:
digitalWrite (LED_PIN, received == 0);  // turn on LED if error

This is sample code from Nick Gammon site, I use hardware serial because softserial is not supported on atmega8:

MASTER:
Code:
#include "RS485_protocol.h"

const byte ENABLE_PIN = 4;
const byte LED_PIN = 13;

// callback routines
 
void fWrite (const byte what)
  {
  Serial.write (what); 
  }
 
int fAvailable ()
  {
  return Serial.available (); 
  }

int fRead ()
  {
  return Serial.read (); 
  }

void setup()
{
  Serial.begin (28800);
  pinMode (ENABLE_PIN, OUTPUT);  // driver output enable
  pinMode (LED_PIN, OUTPUT);  // built-in LED
}  // end of setup
 
byte old_level = 0;

void loop()
{

  // read potentiometer
  byte level = analogRead (0) / 4;
 
  // no change? forget it
  if (level == old_level)
    return;
     
  // assemble message
  byte msg [] = {
     1,    // device 1
     2,    // turn light on
     level // to what level
  };

  // send to slave 
  digitalWrite (ENABLE_PIN, HIGH);  // enable sending
  sendMsg (fWrite, msg, sizeof msg);
  digitalWrite (ENABLE_PIN, LOW);  // disable sending

  // receive response 
  byte buf [10];
  byte received = recvMsg (fAvailable, fRead, buf, sizeof buf);
 
  digitalWrite (LED_PIN, received == 0);  // turn on LED if error   
 
  // only send once per successful change
  if (received)
    old_level = level;

}  // end of loop

SLAVE:
Code:
#include "RS485_protocol.h"

const byte ENABLE_PIN = 4;

void fWrite (const byte what)
  {
  Serial.write (what); 
  }
 
int fAvailable ()
  {
  return Serial.available (); 
  }

int fRead ()
  {
  return Serial.read (); 
  }
 
void setup()
{
  Serial.begin (28800);
  pinMode (ENABLE_PIN, OUTPUT);  // driver output enable
}

void loop()
{
  byte buf [20];
 
  byte received = recvMsg (fAvailable, fRead, buf, sizeof (buf) - 1);
 
  if (received)
    {
    if (buf [0] != 1)
      return;  // not my device
     
    if (buf [1] != 2)
      return;  // unknown command
   
    byte msg [] = {
       0,  // device 0 (master)
       3,  // turn light on command received
    };
   
    delay (1);  // give the master a moment to prepare to receive
    digitalWrite (ENABLE_PIN, HIGH);  // enable sending
    sendMsg (fWrite, msg, sizeof msg);
    digitalWrite (ENABLE_PIN, LOW);  // disable sending
   
    analogWrite (11, buf [2]);  // set light level
   }  // end if something received
   
}  // end of loop end of loop
4  Using Arduino / Networking, Protocols, and Devices / RS485 protocol problem on: June 26, 2014, 01:03:34 pm
Hi everyone,
I am trying to practice with rs485 protocol between two arduinos.
Because I want to expand my project (later) with many more arduinos I am trying to use little more advanced library from Nick Gammon.
Well here is my working code (somewhere from net):
MASTER:
Code:
/* MASTER */
#define TXenable 4

int val = 0;
int incoming = 0;

void setup()
{
  Serial.begin(19200);     
  Serial.println("Serial Master Connected");    //Is not an integer so it won't interfere
  pinMode(TXenable, OUTPUT);
}

void loop()
{
  /*incoming = Serial.available(); 
  while (incoming == 0)     //keep checking until something is available
  {
    incoming = Serial.available();
  }
  Serial.print("Received value... Transmitting:  ");
  val = Serial.parseInt();  //Reads integers as integer rather than ASCI. Anything else returns 0
                            //Note that this is a user input via the Serial Monitor
  */                         
   val = 4;
   digitalWrite(TXenable, HIGH);                         
   Serial.println(val);       //This is being sent to the Rx board
  delay(5000);
}

SLAVE:
Code:
/* SLAVE */
#define TXenable 4
int val = 0;
const int led = 13;
int incoming = 0;

void setup()
{
  Serial.begin(19200);
  Serial.println("Serial Slave Connected");
  pinMode(led, OUTPUT);
  pinMode(TXenable, OUTPUT); 
}

void loop()
{
  incoming = Serial.available();
  while (incoming == 0)                 //Keep checking until there is something available
  {
    incoming = Serial.available();
  }
  digitalWrite(TXenable, LOW);
  val = Serial.parseInt();             //Reads integers as integer rather than ASCI. Anything else returns 0

  for (int i = 0; i < val ; i++)      //Flash the LED the appropriate number of times
  {
    digitalWrite(led, HIGH);   
    delay(100);               
    digitalWrite(led, LOW);   
    delay(100);   
  }
  val = 0;
}

This code is working over rs485, but Nick Gammon library is not working.
Can someone write with Nick library simple code to turn on led on slave arduino?
5  Products / Arduino GSM Shield / USSD code and response on: February 17, 2014, 01:30:41 pm
How to send: AT+CUSD=1,"*121#"
And I get this response:+CUSD: 2,"Stanje na Vasem racunu je 1.00 din. Kredit mozete dopuniti do 18.06.2014. Pozovite *111# i proverite koja vas ponuda ceka.",15

I need to extract text and forward to number who sent request.
6  Using Arduino / Programming Questions / Re: eeprom default state on: February 17, 2014, 12:37:00 pm
SOLVED
I listen advice from KeithRB.
I load sketch example from arduino EEPROM_clear, and after that I load my code and everything work.
7  Using Arduino / Programming Questions / Re: eeprom default state on: February 17, 2014, 11:39:39 am
OK I can change it, but isn't this a chicken-egg problem.
If by default it's 255 and I change it to 240 in setup, and after some time user turn on relay2 (there is power down situation) I save Relay2-ON state to eeprom, and when atmega power on void setup is going to change to 240. And all relays are off again.
So this is my real problem.
8  Using Arduino / Programming Questions / eeprom default state on: February 17, 2014, 11:23:56 am
HI to everybody,
Here is my problem, When sketch start I load state of four pin from variable stored in eeprom address 0.
My problem is that default state is 255, meaning in binary code its 11111111.
And because its gsm controled relays, when I upload sketch I get all four relays enabled, and thats not what I want.
I want to be by default 240 or 11110000.
Here is my code:
Code:
#include <EEPROM.h>
#include <GSM.h> // include the GSM library
#define PINNUMBER "" // PIN Number for the SIM
GSM gsmAccess; // initialize the library instances
GSMScanner scannerNetworks;
GSM_SMS sms;
#define gsm 9 // define pin for startup gsm
int addr = 0; // EEPROM address for storing pin state
unsigned char pins;
char remoteNumber[20];
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.print("Signal Strength: "); //
  Serial.print(scannerNetworks.getSignalStrength()); //
  Serial.println(" [0-31]"); //
  Serial.println(F("Waiting for messages")); //
  showFlags(); //
  Serial.println(freeRam());
}
9  Using Arduino / Programming Questions / Re: Help with "dynamic" statement with string and pin state on: February 16, 2014, 01:33:31 pm
Solved.
Code:
else if (txtmsg.compareTo("status") == 0)
  {
    char stg[32];
    if (digitalRead(pin) == HIGH){
      strcpy(stg, "Relej je ukljucen.");
    }
    else {
      strcpy(stg, "Relej je iskljucen.");
    }
    Serial.println(stg);
    sms.remoteNumber(remoteNumber, 10);
    sms.beginSMS(remoteNumber);
    sms.print(stg);
    sms.endSMS();
  }
10  Using Arduino / Programming Questions / Re: Help with "dynamic" statement with string and pin state on: February 16, 2014, 09:33:00 am
Ok. Thanks for the tip. But when I enter the line
Code:
sms.print(stg);
What is going to print?
11  Using Arduino / Programming Questions / [SOLVED] Help with "dynamic" statement with string and pin state on: February 16, 2014, 07:49:13 am
Here is my code:
Code:
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();
     }
  }
I need to complete the code to do next (my pseudo code)
if txt message is status do next:
if pinstatus == 1
     sting is: relay 'pin' is on
else
string is: relay 'pin' is off
sms.remoteNumber(remoteNumber, 10);
     sms.beginSMS(remoteNumber);
     sms.print(string);
     sms.endSMS();

My brain is stuck, I mean I am stuck at how to create one string with two states.
12  Using Arduino / Microcontrollers / Re: Standalone Arduino Serial debug not working on: February 10, 2014, 06:19:26 pm
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.
13  Using Arduino / Microcontrollers / Re: Standalone Arduino Serial debug not working on: February 10, 2014, 05:43:08 pm
Here are my images
14  Using Arduino / Microcontrollers / Re: Standalone Arduino Serial debug not working on: February 10, 2014, 05:10:40 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.
15  Using Arduino / Microcontrollers / Re: Standalone Arduino Serial debug not working on: February 10, 2014, 04:05:04 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.
Pages: [1] 2 3 4