Getting non arduino library code

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have started looking at using other peripherals with my projects and i program using winavr. Ive looked at using the ESP8266 but its not something someone would build from scratch so i set out looking for a library bit everything seem centered around arduino.

Can anyone offer some advice or ideas. Is it possible to change the arduino units to be independent of the arduino system?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do a search for "Arduino without cores" and read the page at technoblogy.  It describes how to set up an "empty" core which does not have any of the Arduino/Wiring functions.

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For a lot of the driver "libraries" for external I/O, arduino uses its own weird pin numbering system in combination with the horrible "digitalWrite()".

If you replace that part with normal bit manipulation then that is all (or most) that you have to change to use such a lib.

Some of those lib's may also depend on arduino's string manipulation or other parts such as millis().

 

The arduino stuff is about 20 source code files and after compilation it's a few kB.

If you start an arduino project in a decent IDE, instead of the arduino java contraption, then nothing is hidden and you can follow the execution of the lib's code and the exact arduino parts it depends on.

Atmel Studio can directly import an arduino project.

With Platformio you can set up an arduino project for almost any IDE you like.

I use Qt Creator with Platformio, but  it uses Atom by default, which also seems to be a decent IDE.

 

If you have a badly writtten lib however it might be easier to start from scratch from the datasheet, or move on to find a better library.

Rememeber this! Don't waste (too much) time on badly written code.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Sat. Aug 4, 2018 - 12:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ClintonB wrote:
i set out looking for a library bit everything seem centered around arduino.

Including the 100+ previous discussions on this site?  And the ones with specifically your not-Arduino query all concluded that Arduino was necessary to interface that device to AVR8?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

WinAVR is very old.   It only supports elderly AVR models.    WinAvr-2010 was pretty robust.   Earlier versions had some serious "features".

 

I strongly recommend that you stick with the Arduino IDE.    The editor is perfectly usable for writing simple sketches.    And all the libraries,  versions, ... will be reported correctly.

 

If you want to use an external Editor,   you can do this too.

 

Yes,   you can build ESP8266 projects with the Expressif Development System.

I think you will find Arduino easier to get on with.

 

Paulvdh does not like Arduino for some reason.

If you want to go down a non-conformist route,   you will have less help from the worldwide community.

 

Perhaps Paul will give you individual assistance.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would be interested in a non-Arduino way too. Haven't tried to use the ESPs yet but that's gonna change.

Recently I've build a motion activated under bed night light and thought it would be a good idea to try out the arduino stuff. Here's a link to the project documentation if you're interested: https://hackaday.io/project/159725-aurora-motion-activated-underbed-led-light

I changed to plain C because:
1. I was annoyed by the stuff the arduino system is using already (timer)
2. I wasn't able to find out what they're using (did only a quick search but figured that should be enough)
3. Wasn't able to choose which "standard" libraries I really want to use (and remove the rest) without editing the files directly
4. The arduino ecosystem wasn't of any help (except for programming over USB)

But let's get back to the initial question :-)

Regards Max

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Seriously,   if you are annoyed by stuff,   please explain.

 

Arduino starts Timer0 for its system timer e.g. millis(), micros(), delay()

 

It also sets up Timer1 and Timer2 for PWM.    e.g. if you want to produce an AnalogWrite() output (use a low pass filter if you want a d.c. output)

 

If you don't want to use PWM or system timer you can simply set up the Timer registers for your own use.

 

Yes,   you could initialise PWM whenever you call analogWrite()

I would be VERY reluctant to disable the System Timer.

 

You  can write anything you like in plain C.    Codevision makes it very easy to configure a project and provides proven library functions  for many hardware chips

 

Likewise,  GCC can do anything that you want.    You just need to find stuff on the Internet.    And hope that it works.

 

Personally,   I am not proud.    I am happy to use Arduino functions, classes and methods.    Mostly because everyone, anywhere in the world can replicate the code.     And every Arduino can report to a Serial Terminal.

I remember the days when no-one had the same dev kit or set of tools.     And probably had no Serial or LCD.

 

David.

Last Edited: Sat. Aug 4, 2018 - 04:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have been programming AVR's for about 10 years before arduino existed.

I guess they did something right, but I find the thing they call an :IDE" completely unusable.

It hides everything ( compilation process, arduino framework, upload process) and thereby takes away all the tools from you that you need when anything goes wrong.

 

The framework / libraries are "usable" though.

I forced myself to play an hour or so with the arduino "IDE" some time ago, partly out of curiousity, and partly because a few of my friends were interested and some knowledge of "arduino" might help me to help them. I found the "IDE" java contraption cpmpletely horrible and unfit for anything that goes beyond blinking led projects.

 

However, with platfomio you seem to get a very powerfull tool which seems to deliver (almost) everything (or more) that is missing from a "standard arduino" installation.

It even lets you put your project files in the directory you want.

 

With platformio you can also compile / upload ESP8266 projects.

I did a few blinking led projects for an ESP8266 with the arduino framework with platformio and a Wemos D1 mini. It was easy to set up and I had my blinking led within an hour or so with platffomio's command line core. Setting up platformio to use Qt Creator can also be done in 5 minutes once you've figured out how, bit if you're curious about platformio, I recommend to start with a full installation of Platformio, which also installs the Atom IDE by default and that seems to be a decent IDE and a lot better than the arduino's java contraption.

Disadvantage is that the executable for ESP8266 was around 200kB and that takes a while to compile and upload. All the (unused) WiFi stuff was probably also compiled / linked, but I have not looked into that.

 

With the above setup you can also easily follow function calls from your own code into the arduino lib's which makes it a lot easier to figuere out what is going on in those libs and helps with learning how to use them and later maybe extend, extract, or learn from if you're curious, or let them be if you're not interested. At least you have the choice how far you want to go and how much you want to learn.

 

And here on AvrFreaks there are plenty of people to help with problems encountered with (non arduino) AVR related stuff.

 

=============

My biggest aversity against arduino is that it was never intended as a learning platform, and is not very suitable as such (It hides too much), but yet seems to have become the de-facto standard for learning embedded programming and it is the first thing people who have no prior knowledge of programming find and start to use.

"Arduino" would be nothing without GCC, and yet "they" can't even acknowledge that C and C++ are the languages it is build upon and hav invented their own lingo to obfuscate it even more.

This opposes the idea I have of open source and does not make it clear nor obvious how all these free and open tools have grown over the years and have become something wonderfull

(I would not have posted this in the "arduino" thread of avrfreaks, but it does seem well placed in "Compilers and General Programming").

 

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Sat. Aug 4, 2018 - 04:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I regularly use Arduino IDE with:

Uno

Mega2560

Leonardo

M0 Pro (Zero)

Due

Teensy 3.2

Nucleo STM32 F0, F103, F4, L4, ...

BluePill, Maple Mini, ...

ESP8266

ESP32

 

Library code is edited in  Notepad++.    Sketch code in IDE or Notepad++.

 

If PlatformIO works painlessly with all these platforms,   I would consider trying it.

But I would still have to test everything on the proper Arduino IDE before it is released to the rest of the world.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ClintonB wrote:
I have started looking at using other peripherals with my projects and i program using winavr. Ive looked at using the ESP8266 but its not something someone would build from scratch so i set out looking for a library bit everything seem centered around arduino. Can anyone offer some advice or ideas. Is it possible to change the arduino units to be independent of the arduino system?

 

If this might help you... it's a "generic" Makefile that I use to compile "bare" AVR code (that is, no use of Arduino libraries or any other code).

 

It's written fur use in Linux, but you should be easily able to edit it for Windows if you use that.  Note that it's setup to compile code within a directory of the same name.  That is, if your project is "digitalclock.cpp", then the makefile and code should be in a directory named "digitalclock".

 

Hope this is of some use to you (or anyone else for that matter):

 

--------------------------------------------------- cut here ---------------------------------------------------

# avr part
PART=attiny85

 

############## tiny85 fuse settings #############
# internal r/c osc
#F_CPU=8000000UL
#LFUSE=0xE2

 

# external xtal
F_CPU=16000000UL
LFUSE=0xFF

HFUSE=0xDF
EFUSE=0xFF

 

# Atmel AVR-ISP mkii
PGM_PORT=usb
PGM_NAME=stk500v2

 

# Atmel ICE (ICSP mode)
#PGM_PORT=usb
#PGM_NAME=atmelice_isp

 

# Pololu AVR Programmer V2
#PGM_PORT=/dev/serial/by-id/usb-Pololu_Corporation_Pololu_USB_AVR_Programmer_v2.1_00219197-if01
#PGM_NAME=stk500v2

 

PGM_BAUD=115200

 

## our program of course!
TARGET=${notdir ${CURDIR}}

 

## compiler optimization
OPT=O3

 

## uncomment these if you need floating point support
## FLOAT_SUPPORT+=-Wl,-u,vfprintf,-lprintf_flt
## FLOAT_SUPPORT+=-Wl,-u,vfscanf,-lscanf_flt

 

######################################################################
##################### no changes beyond this point ###################
######################################################################

CPPFLAGS+=-Wall
CPPFLAGS+=-fdata-sections
CPPFLAGS+=-ffunction-sections
CPPFLAGS+=-fno-jump-tables
CPPFLAGS+=-mcall-prologues
CPPFLAGS+=-g
CPPFLAGS+=-${OPT}
CPPFLAGS+=-mmcu=${PART}
CPPFLAGS+=-DF_CPU=${F_CPU}
CPPFLAGS+=-MMD
CPPFLAGS+=-MP

 

LDFLAGS+=-mmcu=${PART}
LDFLAGS+=${FLOAT_SUPPORT}
LDFLAGS+=-Wl,--gc-sections
LDFLAGS+=-lm

 

AVR_ERASE+=${AVRDUDE}
AVR_ERASE+=-B 8.0
AVR_ERASE+=-p ${PART}
AVR_ERASE+=-b ${PGM_BAUD}
AVR_ERASE+=-c ${PGM_NAME}
AVR_ERASE+=-P ${PGM_PORT}
AVR_ERASE+=-e
AVR_ERASE+=-s
AVR_ERASE+=-q

 

AVRDUDE_CMD+=${AVR_ERASE}
AVRDUDE_CMD+=-U lfuse:w:${LFUSE}:m
AVRDUDE_CMD+=-U hfuse:w:${HFUSE}:m
AVRDUDE_CMD+=-U efuse:w:${EFUSE}:m
AVRDUDE_CMD+=-U flash:w:${TARGET}.hex:i
AVRDUDE_CMD+=-U eeprom:w:${TARGET}.eep:i

 

SHELL=/bin/bash -c

CC=avr-gcc
CXX=avr-g++
LD=avr-ld
AR=avr-ar
OBJCOPY=avr-objcopy
OBJDUMP=avr-objdump
AVRSIZE=avr-size
AVRDUDE=avrdude
ECHO=echo -en

 

#_______________________________________________________________________________
# BUILD RULES

all: erase build upload

build: ${TARGET} ${TARGET}.hex ${TARGET}.eep
    @${ECHO} "Build of ${TARGET} complete\n"

erase:
    @${AVR_ERASE}
    @${ECHO} "${PART} erased\n"

upload:
    @${AVRDUDE_CMD}
    @${ECHO} "${TARGET} uploaded to ${PART}\n"

clean:
    @${RM} ${TARGET}
    @${RM} ${TARGET}.d
    @${RM} ${TARGET}.eep
    @${RM} ${TARGET}.elf
    @${RM} ${TARGET}.hex
    @${RM} ${TARGET}.o
    @${ECHO} "Build files deleted\n"

 

#_______________________________________________________________________________
# BUILD THE TARGET

%.hex: %
    @$(ECHO) "------------------------------------------------------------\n"
    @$(OBJCOPY) \
    -O ihex \
    -R .eeprom \
    --preserve-dates \
    $(<) $(@)
    @$(AVRSIZE) $(@)
    @$(ECHO) "------------------------------------------------------------\n"

 

%.eep: %
    @$(ECHO) "------------------------------------------------------------\n"
    @$(OBJCOPY) \
    -O ihex \
    -j .eeprom \
    --preserve-dates \
    --no-change-warnings \
    --change-section-lma=.eeprom=0 \
    --set-section-flags=.eeprom=alloc,load \
    $(<) $(@)
    @$(AVRSIZE) $(@)
    @$(ECHO) "------------------------------------------------------------\n"

####### end of Makefile ########

--------------------------------------------------- cut here ---------------------------------------------------

Gentlemen may prefer Blondes, but Real Men prefer Redheads!