Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapt SoftModem lib for ATTiny and other chips #17

Open
jywarren opened this issue Jul 23, 2016 · 32 comments
Open

adapt SoftModem lib for ATTiny and other chips #17

jywarren opened this issue Jul 23, 2016 · 32 comments

Comments

@jywarren
Copy link
Member

https://publiclab.org/notes/rmeister/07-18-2016/webjack-testers-needed#c15006

looking for ATTiny softmodem, i find:

https://github.com/l1q1d/SoftModem-for-attiny85
http://fab.cba.mit.edu/classes/863.12/people/Adam.Marblestone/AHM_week11.html

Maybe we can port in the mods which made it work on the Tiny architecture: l1q1d/SoftModem-for-attiny85@b6f08ca

Also happy to move this to your SoftModem fork instead of having it here

@rmeister
Copy link
Collaborator

Great, thanks for the attiny85 hint! Didn't had that on my radar. Will open a new issue at SoftModem and see what I can do. Unfortunately I don't have an ATTiny, so I can't test it.

@jywarren
Copy link
Member Author

jywarren commented Jul 23, 2016

I'm happy to test, and anyone who has a tinyduino or a digispark can help;
maybe we can ask in one of their forums too.

Also, it might be needed to do the same for Leonardo based arduinos, so
perhaps we can keep that in mind both as another issue to open and in terms
of the code we write and how it's structured (for different chips).

@rmeister
Copy link
Collaborator

rmeister commented Jul 23, 2016

Just pushed the new branch 'attiny-support' at rmeister/SoftModem. You can give it a try, it compiles.

Remeber to:

  • add the ATTiny to the Arduino IDE: http://highlowtech.org/?p=1695
  • change the frequencies in SoftModem.h
  • use SoftwareSerial instead of Serial on the ATTiny

Also I'm not sure if the pins for RX(0) and TX(1) are correct.

This is the sketch I was able to compile:

#include <SoftModem.h>
#include <SoftwareSerial.h>

SoftModem modem = SoftModem();
SoftwareSerial serial(8,9);

void setup() {
  serial.begin(115200);
  serial.println("Booting");
  delay(100);
  modem.begin();
}

void loop() {
  delay(150);
  modem.print("WebJack");
}

@jywarren
Copy link
Member Author

Hmm, i get a bunch of errors like:

/Users/warren/Documents/Arduino/libraries/SoftModem-attiny-support/SoftModem.cpp:113:14: error: 'TCNT2' was not declared in this scope _lastTCNT = TCNT2;

I can test again tomorrow morning, thanks for doing this!

@jywarren
Copy link
Member Author

@rmeister
Copy link
Collaborator

Then probably this did not work:

#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
#define ATTINY 1
#endif

Can you verify that __AVR_ATtiny85__ exists, maybe by using it in a sketch?

@jywarren
Copy link
Member Author

yes but see my latest response to your research note; i think perhaps there's something more basic wrong...

@jywarren
Copy link
Member Author

This compiled:

void setup() {
  // put your setup code here, to run once:

  int i = __AVR_ATtiny85__;

}

void loop() {
  // put your main code here, to run repeatedly:

}

Let me double check that I'm compiling for the right board...

@jywarren
Copy link
Member Author

Taking a closer look at the software serial implementation for the Nanite, I've gotten this to run: https://codebender.cc/sketch:279140#Nanite841%20SoftSerial.ino so i'll adapt that.

@jywarren
Copy link
Member Author

With that Nanite841 sketch, I got to this error:

In file included from /Users/warren/Documents/Arduino/sketch_jul25a/sketch_jul25a.ino:2:0:
/Users/warren/Documents/Arduino/libraries/SoftModem-attiny-support/SoftModem.h:62:20: error: conflicting return type specified for 'virtual size_t SoftModem::write(const uint8_t*, size_t)'
     virtual size_t write(const uint8_t *buffer, size_t size);

                    ^
In file included from /Users/warren/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/cores/tiny/Stream.h:24:0,
                 from /Users/warren/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/cores/tiny/TinyDebugSerial.h:31,
                 from /Users/warren/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/cores/tiny/WProgram.h:18,
                 from /Users/warren/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/cores/tiny/Arduino.h:4,
                 from sketch/sketch_jul25a.ino.cpp:1:
/Users/warren/Library/Arduino15/packages/digistump/hardware/avr/1.6.7/cores/tiny/Print.h:75:18: error:   overriding 'virtual void Print::write(const uint8_t*, size_t)'
     virtual void write(const uint8_t *buffer, size_t size);
                  ^
exit status 1
Error compiling.

@rmeister
Copy link
Collaborator

In the Arduino IDE, I had to choose the ATtiny85 in two steps: first the boad ATtiny 25/45/85 and then the processor itself.

@jywarren
Copy link
Member Author

Hmm, I don't see those. I'm on Arduino IDE 1.6.7, will check for more recent version.

@rmeister
Copy link
Collaborator

Wondering if there is a different between SoftSerial and SoftwareSerial? In the Arduino reference it is always called SoftwareSerial.

@jywarren
Copy link
Member Author

Yes, SoftSerial is a Digispark-provided library I've gotten to work on an ATTiny before, thought I'd try it as an alternative.

@jywarren
Copy link
Member Author

I'm now Arduino IDE 1.6.9, and I don't see ATtiny 25/45/85 in the list; did you install extra boards?

I have to run now, but can give this another go tomorrow. Thanks!

@rmeister
Copy link
Collaborator

Yes I've added this URL to the boad manager: https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
And then installed the 'attiny' package:
board manager

@jywarren
Copy link
Member Author

jywarren commented Jul 25, 2016

Oh great, I'll try that.

@rmeister
Copy link
Collaborator

rmeister commented Aug 1, 2016

Sorry, that package was the wrong track.

From your error log I can see that you already installed the right one: the digistump package. Digistump brings its own implementation of the Print class, which is why the return types of write() are different. At the moment, I solved this problem with conditional compilation.

Also got a Digispark on friday, and to some extend it works with SoftModem (I managed to send data, but no receiving). Though, there is an issues with the ATtiny85: The analog comparator (used for receiving) shares pins with timer 0 (used for generating signals = sending) and therefore interfere, e.g. receiving while sending will not work.

An other problem could be the accurracy of the system clock, that is about 10% if not connected to an USB device.
http://digistump.com/wiki/digispark/tricks#detect_if_system_clock_was_calibrated
Depending on the system's clock, the generated signal will vary.

@jywarren
Copy link
Member Author

jywarren commented Aug 1, 2016

Ah, interesting -- great sleuthing. So what are your next steps or needs?

@rmeister
Copy link
Collaborator

rmeister commented Aug 1, 2016

Think I'll evaluate if it is possible to alternate sending and receiving.

What I forgot to mention is the possibility to change one of the comparator input pins and use an ADC pin instead. But this will disable all other ADC pins. As the purpose of this project is communication for sensors, this is probably not beneficial.

@rmeister
Copy link
Collaborator

rmeister commented Aug 1, 2016

And if you feel lucky, you can give your digispark a try 😄 https://github.com/rmeister/SoftModem/tree/attiny-support
The output is on pin 1.

@rmeister
Copy link
Collaborator

rmeister commented Aug 3, 2016

Leonardo will also be able to generate now. TX pin is 3, like for the Uno.

@jywarren
Copy link
Member Author

jywarren commented Aug 4, 2016

hoping to get to this tonight; we'll see!

@jywarren
Copy link
Member Author

jywarren commented Aug 5, 2016

I was able to successfully upload the test sketch onto both a Leonardo and a Digispark; I'll try attaching a headphone cable tomorrow!

@jywarren
Copy link
Member Author

jywarren commented Aug 5, 2016

The Leonardo uploaded with the simple example sketch you provided here: https://publiclab.org/notes/rmeister/07-18-2016/webjack-testers-needed#2.+Load+this+sketch+to+the+Arduino

@jywarren
Copy link
Member Author

jywarren commented Aug 5, 2016

Digispark blinks promisingly but I realized I have the wrong headphone plug... I'm going to try to grab another and modify but I am travelling this week, so hard to say.

@rmeister
Copy link
Collaborator

rmeister commented Aug 5, 2016

Cool, blinking sounds promising. Thanks for your effort!

@jywarren
Copy link
Member Author

jywarren commented Aug 5, 2016

I wasn't able to find an affordable four pin cable at the airport, but I'm
going to try to get headphones on the plane and attach a speaker to the
digispark, then hold it up to the laptop microphone.

...maybe after I land.

Else I may be able to find a cheaper cable or a broken apple headset
soonish. I actually have both a Leonardo and a digispark with me. I have a
nanite too, but not sure I can flash that from codebender, and only have a
Chromebook at the moment.

Eventually I hope well be able to program over audio too :-)

@jywarren
Copy link
Member Author

OK, I was able to connect the Leonardo to the audio in, and confirm it's being played into the computer. This was with no extra circuitry -- just directly into the audio port.

https://i.publiclab.org/system/images/photos/000/017/613/original/leonardo-webjack.mov

But I didn't see it read by the webjack demo. Maybe it's blowing out with too much amplitude?

@rmeister
Copy link
Collaborator

rmeister commented Aug 15, 2016

leonardo_direct_input

Looks a little distorted. But one can see the preamble and some bits following (with a larger zoom factor than in this picture). Maybe you can reduce the amplifying of the mic?

@jywarren
Copy link
Member Author

Followup: I got the Leonardo sending, but not receiving (as you noted) using https://github.com/rmeister/SoftModem/tree/attiny-support. What would it take to get receiving working? Is this a timer issue as in the ATTiny side of things? Thanks!

@jywarren
Copy link
Member Author

Sorry, moving last question to arms22/SoftModem#5

@jywarren jywarren pinned this issue May 5, 2019
@jywarren jywarren changed the title adapt SoftModem lib for ATTiny chips adapt SoftModem lib for ATTiny and other chips May 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants