Show Posts
Pages: [1]
1  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: August 31, 2014, 05:39:51 pm
Update: I checked the SoftUART putchar() code and it could return a negative value and cause higher functions to think it was EOF or an error. There is an update that fixes this. https://github.com/mikaelpatel/Cosa/commit/d26d0d46eecd6b10e5d27f288bfd72a31a4692a1

Great catch! I've written a small test program which clearly proves that this is the problem:
Code:
class DevTest : public IOStream::Device {
   
public:
    volatile char last;
   
    int putchar(char c) {
        last = c;
    }
};


DevTest testDev;
Soft::UART sUart(Board::D9, Board::PCI8, &testDev); // RX on D8

void setup() {
    uart.begin(57600);
    sUart.begin(9600);
   
    trace.begin(&uart, PSTR("Test code started"));
}

void loop() {
    char printed = 0;
    while (1) {
        if (testDev.last != printed) {
            printed = testDev.last;
            INFO("Seen %d", printed);
        }
    }
    while (sUart.available()) {
        INFO("Received character with code: %d", sUart.getchar());
    }
}

This is the output I get while feeding in increasing byte values:
Code:
82:void loop():info:Seen 121
82:void loop():info:Seen 122
82:void loop():info:Seen 123
82:void loop():info:Seen 124
82:void loop():info:Seen 125
82:void loop():info:Seen 126
82:void loop():info:Seen 127
82:void loop():info:Seen -128
82:void loop():info:Seen -127
82:void loop():info:Seen -126
82:void loop():info:Seen -125
82:void loop():info:Seen -124
82:void loop():info:Seen -123
82:void loop():info:Seen -122
82:void loop():info:Seen -121

I've applied your patch but this did not fix the issue. I finally realized that 'char' is 8bit signed… As soon as I moved from char to uint8_t my problems are solved. Your patch does not change the behavior in my specific case. I've simply chosen the wrong data type. So I'm back on track, thanks for your support.

I'll continue to investigate how Cosa is working. Really love what I've seen so far. Thanks again…
2  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: August 31, 2014, 11:10:48 am
Interesting stuff going on here! I just stumbled upon Cosa and it looks very nice.

After some easy examples I tried to migrate a NMEA (GPS messages) parser library I wrote. The library works in-stream, every character is parsed as it arrives and not put in a buffer to be parsed later. It uses very little memory and is fast. It looked like a great idea to implement it as a subclass to IOStream::Device and attach it as input buffer to a SoftUART instance.

Good news first: It worked more or less on first try. As it is a IOStream::Device it actually executes inside the interrupt where the new characters are received and works completely in the background. Perfect! The Arduino-version also uses UBX messages (a proprietary protocol used by uBlox GPS receivers) but I can't bring this to life on Cosa. I'm able to send UBX commands which are executed on the GPS module but I never receive the answer. I see the answers "on wire" using a logic analyzer but the data is not sent to IOStream::Device::put char(char c). Any ideas why this could happen? Why do I get every NMEA message without problems but it just kinda skips the UBX messages? NMEA is only using 7bit ASCII and UBX messages start with a 0xB5 byte. Is there some kind of 8bit mode I have to activate first?

I may have a chance to work around this and completely ditching UBX messages but I'm still interested why it does not work.

Is there a place where there are some How-To's regarding Cosa? I found the blog on blogspot but it doesn't look complete at all. Sure, the API is documented but for me this is not enough to understand the concepts and ideas behind the whole library (Events, Multi-Threading, ...).

Thanks for taking time to read though my message…
3  Development / Other Software Development / Re: State of Arduino Ethernet Library on: January 05, 2013, 04:23:07 pm
We are together here. I see where you are going, but it may require more than meets the eye. How would you tell the devices apart before compile? You must select the correct Arduino board in the IDE before compile. It does not even do that automatically.

I thought maybe using a different ethernet library include file for each. I wouldn't want to include all the code for every ethernet device, just the one I am using.
Code:
#include <Ethernet.h>
// or
#include <Ethernet5200.h>
// or
#include <Ethernet28J60.h>

All could include the same functions with the same parameters and return values as the current ethernet library.
Ethernet.begin()
server.available()
client.read()
client.println()
client.stop()
...and the like, don't you think?


That's what I'm looking at too. Actually I found a nice solution where there is one common, device-independent Ethernet class which is never used directly but only as interface. The actual implementation is EthernetW5200 which could easily be replaced with other implementations. What I like about my solution is that there is absolutely no change needed in the library files. The 'include' in the Sketch decides about the implementation. What I don't like about this solution is the amount of work which has to be done before this'll work. TCP and UDP implementation are tightly coupled to the W5x00 module.

W5100 and W5200 are almost identical, so it's possible to do them in the same sourcecode files but I doubt it's the same with ENC28J60 and others. IMHO this is only a short-term solution.

I've already uploaded some stuff to github too. It's not much more than a proof-of-concept but it already shows that it's possible to include different header files to select an implementation. Here's what I did:
* Made EthernetClass an abstract class which'll be the only interface used by all protocol implementations.
* Changed EthernetW5200 class so it inherits methods from the EthernetClass
* The Sketch now has to include one implementation and assign it to the global variable 'Ethernet'
* All protocol implementations are unchanged but won't work until they are freed from the direct calls to W5x00.*

And finally the link: https://github.com/tht/ArduinoEthernetGeneric

I won't be able to spend much time on it for a few weeks but it's a start and shows a possible way to go.
4  Development / Other Software Development / Re: State of Arduino Ethernet Library on: January 03, 2013, 08:20:01 am
Thanks for your fast reply. Looks like we're thinking in the same direction.

This is just a transport, not a protocol. Setting up the transport should be rather universal. I mean, how much is there to it? mac, ip, subnet, gateway, dns, dhcp.

For me the transport-layer should provide stuff like: mac, ip, subnet, gateway, sockets (open, close, send, getFreeTxSpace, getBytesAvailable). I'm quite sure it's possible to abstract this for (at least) the most common Ethernet chips out there.

Currently all implemented protocols (EthernetUDP, EthernetClient, DNS and DHCP) do include the w5100.h which binds it to this specific chipset. Some people just replace the content of the w5100.h,.cpp files with a driver for the W5200 chip. I don't like this workaround at all...

I only had to replace two functions (and some minor adjustments) in W5100.cpp and it worked for a W5200 on a 32bit ARM Cortex-M4 CPU. This is just great! The different layers (transport, IP/UDP, highlevel-protocol using TCP/UDP) are already layered how it should be but the binding is too tight.

Actually I don't know much about inheritance, interfaces, linking and stuff like this in C++ as I do have a Java background. Shouldn't this be possible?
5  Development / Other Software Development / State of Arduino Ethernet Library on: January 02, 2013, 07:09:47 am
I'm new to the Ethernet Library so please excuse if I make some wrong assumptions here. I'm just looking for a more generic way to do things.

  • Is there someone maintaining the Library? I could not find a name anywhere.
  • Looks like the whole library is only useful for W5100 chips, every file links to it.
  • Why not extract a generic interface which could support multiple implementations?
  • DHCP works nicely but what's about DNS? The existing code does not work for me.

I'm asking because I ported this library to the W5200 on a Teensy3. Almost all code is identical to the Ethernet library but I had to replace this <<#include "w5100.h">> in every single file.

For me it looks like more or less every Ethernet chipset should be usable through one generic interface… Is there someone interested in this? What about the original author(s) of the Ethernet Library?

cheers,
Thomas
6  Using Arduino / Storage / Re: New SdFat optimized for Mega and Teensy 3.0 on: October 25, 2012, 12:27:06 pm
The pin multiplexing mode – of course! That has to be the solution. Thank you!
7  Using Arduino / Storage / Re: New SdFat optimized for Mega and Teensy 3.0 on: October 24, 2012, 02:35:39 pm
Where you able to use the ChipSelect-feature too? I set all the PCS bits in PUSHR but it never touches the CS state. This is my actual code:
Code:
inline uint16_t RF12_T3::rf12_xfer(uint16_t data) {
//  digitalWriteFast(10, LOW);
  SPI0_PUSHR = (1<<26) | (B11111 << 16) | data;    // send data (clear transfer counter, select all CS)
  while (! SPI0_TCR) ; // loop until transfer is complete
//  digitalWriteFast(10, HIGH);
  return SPI0_POPR;
}

Configuration is like this:
Code:
  // enables and configures SPI module
  // 16MHz 16bit transfers on CTAR0
  SPI0_CTAR0 = 0xF8010000;

Sorry for being a bit off-topic...
8  Using Arduino / Project Guidance / Re: How to optimize my code for future use? on: July 19, 2012, 04:43:38 am
If your goal is to save energy, put all data into a struct and send this struct. So all is packed quite well. There is, of course, a downside... reading the data at the receiver is harder if this part is not also written in C:

Code:
struct {
    float humi;
    float temp;
} payload;

9  Development / Other Software Development / Update Arduino Toolchain on OS X on: February 12, 2012, 04:27:15 am
I actually did hope for one more reply from you :-)

It's not the first time I run into a problem with the Arduino 1.0 toolchain. It's a 1.0 - there have to be problems  smiley-lol

Thanks for the links, google actually wasn't really useful on this problem. Too bad I can't use your install instructions as I'm running Arduino on OS X, not Windows. WinAVR sounds a little bit like a Windows application…

I just found a nice OS X package with all the required files. Here's how to install it:

Code:
cd /Applications/Arduino.app/Contents/Resources/Java/hardware/tools
mv avr avr-old
ln -s /usr/local/CrossPack-AVR avr

For me it works perfect (until now…)
Done compiling.
Binary sketch size: 4966 bytes (of a 8192 byte maximum)
10  Development / Other Software Development / Re: Need help porting OneWire.h to ATtiny84 on: February 12, 2012, 03:42:31 am
Works great, thank you!

Next problem already arrived…
Code:
hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn84.o:(.init9+0x0): relocation truncated to fit: R_AVR_13_PCREL against symbol `main' defined in .text.main section in core.a(main.cpp.o)
hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn84.o:(.init9+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25/libgcc.a(_exit.o)

The problem goes away when I remove all references to OneWire OR rfm12b. Looks like some kind of resource problem. It's not the sketch-size, it has to be something else… I'll try to restructure my code.
11  Development / Other Software Development / Re: Need help porting OneWire.h to ATtiny84 on: February 11, 2012, 06:31:05 pm
I got version 2.1 from here:
http://www.pjrc.com/teensy/td_libs_OneWire.html

Good idea, I wasn't looking for another library (until now…).
12  Development / Other Software Development / [solved] Need help porting OneWire.h to ATtiny84 on: February 11, 2012, 04:30:32 pm
Hi,

I just registered to this forum but I already know the Arduino platform, C and some hardware stuff. I'm working on a small project where I have to read one analog sensor and a 1wire device (DS18B20). The data has to be sent using a RFM12B module. Looks like my only problem is the OneWire library…

I'm using Arduino 1.0 on OS X and have installed the latest version of the arduino-tiny library from http://code.google.com/p/arduino-tiny/

When I try to compile the code I get these errors:
Code:
Documents/Arduino_1.0/libraries/OneWire/OneWire.cpp: In constructor 'OneWire::OneWire(uint8_t)':
Documents/Arduino_1.0/libraries/OneWire/OneWire.cpp:105: error: 'digitalPinToBitMask' was not declared in this scope
Documents/Arduino_1.0/libraries/OneWire/OneWire.cpp:106: error: 'digitalPinToPort' was not declared in this scope
Documents/Arduino_1.0/libraries/OneWire/OneWire.cpp:106: error: 'portInputRegister' was not declared in this scope

I'm a bit confused because all these functions are defined in Arduino_1.0/hardware/tiny/cores/tiny/pins_arduino.h. Actually these are not functions but preprocessor macros but why doesn't this work?

I'm planning to make some custom pcb's and don't like the idea to go to a ATmega only because of this 1wire library… Any ideas? I could provide some demo-code if needed.

Thanks!
Pages: [1]